pluginPipeline: DRY out set-java.sh in bash shells

DRY-out existing calls to set-java.sh into a new bashSetJavaCmd
and reuse it throughout the script.

Also add the call to bashSetJavaCmd into GJF calls for preventing
failures of GJF v1.24 with running with a default Java 25.

Change-Id: I477949cf55ff61f082f94d477c85163a3ed8177c
diff --git a/vars/pluginPipeline.groovy b/vars/pluginPipeline.groovy
index edd8b19..c750c4e 100644
--- a/vars/pluginPipeline.groovy
+++ b/vars/pluginPipeline.groovy
@@ -42,7 +42,8 @@
     def defaultGjfVersion =
         env.GERRIT_BRANCH ==~ /stable-3\.(11|12|13|14)/ ? '1.24.0' : '1.35.0'
     def gjfVersion = parm.gjfVersion ?: defaultGjfVersion
-    def bazeliskCmd = "#!/bin/bash\n" + ". set-java.sh --branch $GERRIT_BRANCH && bazelisk"
+    def bashSetJavaCmd = "#!/bin/bash\n" + ". set-java.sh --branch $GERRIT_BRANCH"
+    def bazeliskCmd = "${bashSetJavaCmd} bazelisk"
     def bazeliskOptions = "--sandbox_tmpfs_path=/tmp"
     def gerritReviewCredentialsId = "gerrit.googlesource.com"
     def githubBaseUrl = ""
@@ -87,7 +88,7 @@
                 }
                 steps {
                     gerritCheck (checks: ["${formatCheck}": 'RUNNING'], url: "${env.BUILD_URL}console")
-                    sh "find ${pluginName} -name '*.java' | xargs /home/jenkins/format/google-java-format-${gjfVersion} -i"
+                    sh "${bashSetJavaCmd} && find ${pluginName} -name '*.java' | xargs /home/jenkins/format/google-java-format-${gjfVersion} -i"
                     script {
                         def formatOut = sh (script: "cd ${pluginName} && git status --porcelain", returnStdout: true)
                         if (formatOut.trim()) {
@@ -113,7 +114,7 @@
                             (extraPlugins + extraModules + extraGhRepos).each { plugin -> sh "cd plugins && ln -s ../../${plugin} ." }
                         }
                         sh "${bazeliskCmd} build ${bazeliskOptions} gerrit"
-                        sh "#!/bin/bash\n" + ". set-java.sh --branch $GERRIT_BRANCH && ./polygerrit-ui/app/api/publish.sh --pack"
+                        sh "${bashSetJavaCmd} && ./polygerrit-ui/app/api/publish.sh --pack"
                         sh "${bazeliskCmd} build ${bazeliskOptions} plugins/${pluginName}/..."
                         sh "${bazeliskCmd} test ${bazeliskOptions} --test_env DOCKER_HOST=" + '$DOCKER_HOST' + " plugins/${pluginName}/..."
                     }