Build gerrit-support plugins on different branches

Change-Id: I5ad6a0f813693973b712647154e38cc50ebb1693
diff --git a/jenkins/gerrit-sbt-build-branch-plugin.sh b/jenkins/gerrit-sbt-build-branch-plugin.sh
new file mode 100644
index 0000000..f5f2564
--- /dev/null
+++ b/jenkins/gerrit-sbt-build-branch-plugin.sh
@@ -0,0 +1,28 @@
+#!/bin/bash -e
+
+if [ -f "gerrit/BUILD" ]
+then
+  git read-tree -u --prefix=gerrit gerrit/{gerrit-branch}
+  . set-java.sh 8
+
+  pushd gerrit
+  bazel build api
+  ./tools/maven/api.sh install
+  popd
+fi
+
+sbt -no-colors compile test assembly
+
+# Extract version information
+PLUGIN_JARS=$(find . -name '{name}*jar')
+for jar in $PLUGIN_JARS
+do
+  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" > $jar-version
+
+  curl -L https://gerrit-review.googlesource.com/projects/plugins%2F{name}/config | \
+     tail -n +2 > $(dirname $jar)/$(basename $jar .jar).json
+done
diff --git a/jenkins/gerrit-sbt-build-plugin.sh b/jenkins/gerrit-sbt-build-plugin.sh
index f5f2564..d672add 100644
--- a/jenkins/gerrit-sbt-build-plugin.sh
+++ b/jenkins/gerrit-sbt-build-plugin.sh
@@ -2,7 +2,7 @@
 
 if [ -f "gerrit/BUILD" ]
 then
-  git read-tree -u --prefix=gerrit gerrit/{gerrit-branch}
+  git read-tree -u --prefix=gerrit gerrit/{branch}
   . set-java.sh 8
 
   pushd gerrit
diff --git a/jenkins/gerrit-sbt-plugin-gerrit-support.yaml b/jenkins/gerrit-sbt-plugin-gerrit-support.yaml
index 1543d06..6dd9d2c 100644
--- a/jenkins/gerrit-sbt-plugin-gerrit-support.yaml
+++ b/jenkins/gerrit-sbt-plugin-gerrit-support.yaml
@@ -1,11 +1,7 @@
 - project:
     name: gerrit-support
     jobs:
-      - 'plugin-{name}-sbt-{branch}-{gerrit-branch}':
+      - 'plugin-{name}-sbt-{branch}':
           branch:
             - master
-          gerrit-branch:
-            - master
-            - stable-2.15
             - stable-2.14
-            - stable-2.13
diff --git a/jenkins/gerrit-sbt-plugin-template.yaml b/jenkins/gerrit-sbt-plugin-template.yaml
index 08c05d9..dbfdff6 100644
--- a/jenkins/gerrit-sbt-plugin-template.yaml
+++ b/jenkins/gerrit-sbt-plugin-template.yaml
@@ -1,6 +1,5 @@
-- job-template:
-    name: 'plugin-{name}-sbt-{branch}-{gerrit-branch}'
-    description: "Plugin {name} {branch} branch build with Sbt on top of Gerrit {gerrit-branch}\n"
+- defaults:
+    name: sbt-build-defaults
     node: sbt
     wrappers:
       - timeout:
@@ -37,7 +36,7 @@
 
     builders:
       - shell:
-         !include-raw: gerrit-sbt-build-plugin.sh
+         !include-raw: gerrit-sbt-build-branch-plugin.sh
     publishers:
       - archive:
          artifacts: '**/target/**/{name}*.jar*,**/target/**/{name}*.json'
@@ -45,3 +44,19 @@
     wrappers:
       - raw:
           xml: <jenkins.plugins.logstash.LogstashBuildWrapper plugin="logstash@1.2.0"/>
+
+- job-template:
+    name: 'plugin-{name}-sbt-{branch}-{gerrit-branch}'
+    description: "Plugin {name} {branch} branch build with Sbt on top of Gerrit {gerrit-branch}\n"
+    defaults: sbt-build-defaults
+    builders:
+      - shell:
+         !include-raw: gerrit-sbt-build-branch-plugin.sh
+
+- job-template:
+    name: 'plugin-{name}-sbt-{branch}'
+    description: "Plugin {name} build with Sbt on top of Gerrit {branch}\n"
+    defaults: sbt-build-defaults
+    builders:
+      - shell:
+         !include-raw: gerrit-sbt-build-plugin.sh