Add multiple targets build for zookeeper-refdb plugin

Zookeeper-refdb plugin builds with two zookeeper
versions (3.4.x and 3.5.x)

Also add the ability to add extra artifacts to the build
by using a new 'extra-artifact' parameter.

Feature: Issue 12583
Change-Id: Ia62c8bbfe1c31bce197aae52bc0070881cef09aa
diff --git a/jenkins/gerrit-bazel-build-plugin.sh b/jenkins/gerrit-bazel-build-plugin.sh
index 700fb0e..8f51158 100644
--- a/jenkins/gerrit-bazel-build-plugin.sh
+++ b/jenkins/gerrit-bazel-build-plugin.sh
@@ -22,11 +22,12 @@
 bazelisk build --spawn_strategy=standalone --genrule_strategy=standalone $TARGETS
 bazelisk test --test_env DOCKER_HOST=$DOCKER_HOST //tools/bzl:always_pass_test plugins/{name}/...
 
-JAR="bazel-bin/plugins/{name}/{name}.jar"
-if test -f $JAR
-then
-  PLUGIN_VERSION=$(git describe  --always origin/{branch})
-  echo -e "Implementation-Version: $PLUGIN_VERSION" > MANIFEST.MF
-  jar ufm $JAR MANIFEST.MF && rm MANIFEST.MF
-  echo "$PLUGIN_VERSION" > bazel-bin/plugins/{name}/$(basename $JAR-version)
-fi
+for JAR in $(find bazel-bin/plugins/{name} -maxdepth 1 -name {name}*.jar)
+do
+    PLUGIN_VERSION=$(git describe  --always origin/{branch})
+    echo -e "Implementation-Version: $PLUGIN_VERSION" > MANIFEST.MF
+    jar ufm $JAR MANIFEST.MF && rm MANIFEST.MF
+    DEST_JAR=bazel-bin/plugins/{name}/$(basename $JAR)
+    [ "$JAR" -ef "$DEST_JAR" ] || mv $JAR $DEST_JAR
+    echo "$PLUGIN_VERSION" > bazel-bin/plugins/{name}/$(basename $JAR-version)
+done
diff --git a/jenkins/gerrit-bazel-plugin-template.yaml b/jenkins/gerrit-bazel-plugin-template.yaml
index 7a56075..02760d5 100644
--- a/jenkins/gerrit-bazel-plugin-template.yaml
+++ b/jenkins/gerrit-bazel-plugin-template.yaml
@@ -54,6 +54,7 @@
     node: bazel-debian
     class: plugins
     project-name: plugins%2F{name}
+    extra-artifacts: ''
     scm:
       - git:
           remotes:
@@ -79,7 +80,8 @@
           artifacts: >
             bazel-bin/plugins/{name}/{name}.jar,
             bazel-bin/plugins/{name}/{name}.jar-version,
-            bazel-bin/plugins/{name}/{name}.json
+            bazel-bin/plugins/{name}/{name}.json,
+            {extra-artifacts}
 
 - job-template:
     name: 'ui-plugin-{name}-bazel-{branch}'
@@ -88,6 +90,7 @@
     node: bazel-debian
     class: plugins
     project-name: plugins%2F{name}
+    extra-artifacts: ''
     scm:
       - git:
           remotes:
@@ -113,7 +116,8 @@
           artifacts: >
             bazel-bin/plugins/{name}/{name}.js,
             bazel-bin/plugins/{name}/{name}.html,
-            bazel-bin/plugins/{name}/{name}.json
+            bazel-bin/plugins/{name}/{name}.json,
+            {extra-artifacts}
 
 - job-template:
     name: 'plugin-{name}-bazel-{branch}-{gerrit-branch}'
@@ -121,6 +125,7 @@
     node: bazel-debian
     description: 'Plugin {name} {branch} branch Bazel build for Gerrit {gerrit-branch}'
     defaults: plugin-template-bazel
+    extra-artifacts: ''
     scm:
       - git:
           remotes:
@@ -139,7 +144,8 @@
           artifacts: >
             bazel-bin/plugins/{name}/{name}.jar,
             bazel-bin/plugins/{name}/{name}.jar-version,
-            bazel-bin/plugins/{name}/{name}.json
+            bazel-bin/plugins/{name}/{name}.json,
+            {extra-artifacts}
 
 - job-template:
     name: 'module-{name}-bazel-{branch}-{gerrit-branch}'
@@ -147,6 +153,7 @@
     node: bazel-debian
     description: 'Lib module {name} {branch} branch Bazel build for Gerrit {gerrit-branch}'
     defaults: plugin-template-bazel
+    extra-artifacts: ''
     scm:
       - git:
           remotes:
@@ -165,7 +172,8 @@
           artifacts: >
             bazel-bin/plugins/{name}/{name}.jar,
             bazel-bin/plugins/{name}/{name}.jar-version,
-            bazel-bin/plugins/{name}/{name}.json
+            bazel-bin/plugins/{name}/{name}.json,
+            {extra-artifacts}
 
 - job-template:
     name: 'module-{name}-bazel-{branch}'
@@ -173,6 +181,7 @@
     node: bazel-debian
     description: 'Lib module {name} {branch} branch Bazel build'
     defaults: plugin-template-bazel
+    extra-artifacts: ''
     scm:
       - git:
           remotes:
@@ -195,7 +204,8 @@
           artifacts: >
             bazel-bin/plugins/{name}/{name}.jar,
             bazel-bin/plugins/{name}/{name}.jar-version,
-            bazel-bin/plugins/{name}/{name}.json
+            bazel-bin/plugins/{name}/{name}.json,
+            {extra-artifacts}
 
 - view-template:
     name: 'Plugins-{branch}'
diff --git a/jenkins/gerrit-bazel-plugin-zookeeper-refdb.yaml b/jenkins/gerrit-bazel-plugin-zookeeper-refdb.yaml
index 12f35a1..d9fdd5e 100644
--- a/jenkins/gerrit-bazel-plugin-zookeeper-refdb.yaml
+++ b/jenkins/gerrit-bazel-plugin-zookeeper-refdb.yaml
@@ -4,7 +4,11 @@
       - 'plugin-{name}-bazel-{branch}':
           branch:
             - master
-            - stable-3.2
             - stable-3.1
             - stable-3.0
+      - 'plugin-{name}-bazel-{branch}':
+          targets: "plugins/{name}:{name} plugins/{name}:{name}-zk-3.5"
+          branch:
+            - stable-3.2
+          extra-artifacts: 'bazel-bin/plugins/{name}/{name}-zk-3.5.jar'
       - 'plugin-{name}-verifier'