Avoid shell parameter expansion in JJB scripts
Jenkins Job Builder treats {} specially, which conflicts with the
shell default-value expansion ${BAZEL_MAJOR:-0} used in the Bazel
version check. Attempting to escape it with doubled braces results in
an invalid shell expression in the generated script.
Avoid parameter expansion altogether by assigning a default value
explicitly before the numeric comparison.
This keeps the Bazel >= 9 check working correctly in both Jenkins shell
wrappers.
Change-Id: I1abd35f6ffa5424265848d04ba62fabda0aa1904
diff --git a/jenkins/gerrit-bazel-build.sh b/jenkins/gerrit-bazel-build.sh
index af91216..d31d6fa 100644
--- a/jenkins/gerrit-bazel-build.sh
+++ b/jenkins/gerrit-bazel-build.sh
@@ -22,7 +22,8 @@
echo "$BAZEL_VERSION_OUTPUT"
BAZEL_MAJOR=$(echo "$BAZEL_VERSION_OUTPUT" | sed -n 's/^Build label: \([0-9][0-9]*\).*/\1/p')
-if [ "${{BAZEL_MAJOR:-0}}" -ge 9 ]; then
+[ -n "$BAZEL_MAJOR" ] || BAZEL_MAJOR=0
+if [ "$BAZEL_MAJOR" -ge 9 ]; then
echo "Skipping bazel sync for Bazel $BAZEL_MAJOR"
else
echo "Running bazel sync for Bazel $BAZEL_MAJOR"
diff --git a/jenkins/gerrit-mvn-build-plugin.sh b/jenkins/gerrit-mvn-build-plugin.sh
index bdde14e..6bc40f4 100644
--- a/jenkins/gerrit-mvn-build-plugin.sh
+++ b/jenkins/gerrit-mvn-build-plugin.sh
@@ -20,7 +20,8 @@
fi
BAZEL_MAJOR=$(echo "$BAZEL_VERSION_OUTPUT" | sed -n 's/^Build label: \([0-9][0-9]*\).*/\1/p')
-if [ "${{BAZEL_MAJOR:-0}}" -ge 9 ]; then
+[ -n "$BAZEL_MAJOR" ] || BAZEL_MAJOR=0
+if [ "$BAZEL_MAJOR" -ge 9 ]; then
echo "Skipping bazel sync for Bazel $BAZEL_MAJOR"
else
echo "Running bazel sync for Bazel $BAZEL_MAJOR"