Bazel 9 removed the `sync` command, causing CI failures: Command 'sync' not found Run `bazel sync` only for Bazel versions older than 9 by checking the major version. This keeps the behavior unchanged for older Bazel versions while allowing CI to work with Bazel 9 and newer. Change-Id: Ia0490f3ecca3196dc9ed7cc4786dda76f311650d
diff --git a/jenkins/gerrit-bazel-build.sh b/jenkins/gerrit-bazel-build.sh index eac1990..d461927 100644 --- a/jenkins/gerrit-bazel-build.sh +++ b/jenkins/gerrit-bazel-build.sh
@@ -17,12 +17,20 @@ echo '----------------------------------------------' java -fullversion -bazelisk version -# Whilst all the rest of Gerrit is able to automatically sync the Bazel repositories -# the PolyGerrit part fails to do so when the working directory is replaced with a -# fresh clone from the remote Git repository -bazelisk sync --only=npm --only=tools_npm --only=ui_npm --only=plugins_npm +BAZEL_VERSION_OUTPUT=$(bazelisk version 2>/dev/null) +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 + echo "Skipping bazel sync for Bazel $BAZEL_MAJOR" +else + echo "Running bazel sync for Bazel $BAZEL_MAJOR" + # Whilst all the rest of Gerrit is able to automatically sync the Bazel repositories + # the PolyGerrit part fails to do so when the working directory is replaced with a + # fresh clone from the remote Git repository + bazelisk sync --only=npm --only=tools_npm --only=ui_npm --only=plugins_npm +fi if [[ "$MODE" == *"rbe"* ]] then
diff --git a/jenkins/gerrit-mvn-build-plugin.sh b/jenkins/gerrit-mvn-build-plugin.sh index 7d06ace..c5468d6 100644 --- a/jenkins/gerrit-mvn-build-plugin.sh +++ b/jenkins/gerrit-mvn-build-plugin.sh
@@ -5,7 +5,9 @@ git checkout -f -b gerrit-master gerrit/{branch} git submodule update --init java -fullversion -bazelisk version + +BAZEL_VERSION_OUTPUT=$(bazelisk version 2>/dev/null) +echo "$BAZEL_VERSION_OUTPUT" # This is a workaround to Issue 316936462: after the initial build with $BAZEL_OPTS # that include a remote cache, the subsequent implicit build commands executed would @@ -17,10 +19,16 @@ echo "build $BAZEL_OPTS" >> .bazelrc fi -# Whilst all the rest of Gerrit is able to automatically sync the Bazel repositories -# the PolyGerrit part fails to do so when the working directory is replaced with a -# fresh clone from the remote Git repository -bazelisk sync --only=npm --only=tools_npm --only=ui_npm --only=plugins_npm +BAZEL_MAJOR=$(echo "$BAZEL_VERSION_OUTPUT" | sed -n 's/^Build label: \([0-9][0-9]*\).*/\1/p') +if [ "${BAZEL_MAJOR:-0}" -ge 9 ]; then + echo "Skipping bazel sync for Bazel $BAZEL_MAJOR" +else + echo "Running bazel sync for Bazel $BAZEL_MAJOR" + # Whilst all the rest of Gerrit is able to automatically sync the Bazel repositories + # the PolyGerrit part fails to do so when the working directory is replaced with a + # fresh clone from the remote Git repository + bazelisk sync --only=npm --only=tools_npm --only=ui_npm --only=plugins_npm +fi bazelisk build api ./tools/maven/api.sh install