Update to support Plugins built with Bazel

Extend existing Buck templates to include a Bazel build definition.
Existing plugin jobs names are kept 'as-is' to avoid loosing the
artifacts already built.

Change-Id: I42c07fdcaf174b5d6bbc43f176d9f6e94f3eec74
diff --git a/jenkins/gerrit-bazel-build-plugin.sh b/jenkins/gerrit-bazel-build-plugin.sh
new file mode 100644
index 0000000..c8dbe4a
--- /dev/null
+++ b/jenkins/gerrit-bazel-build-plugin.sh
@@ -0,0 +1,21 @@
+#!/bin/bash -e
+
+git checkout -f gerrit/{branch}
+rm -rf plugins/{name}
+git read-tree -u --prefix=plugins/{name} origin/{branch}
+
+TARGETS=$(echo "{targets}" | sed -e 's/{{name}}/{name}/g')
+
+. set-java.sh 8
+
+bazel build --spawn_strategy=standalone --genrule_strategy=standalone -v 3 $TARGETS
+
+for JAR in $(bazel targets --show_output $TARGETS | awk '{{print $2}}')
+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-genfiles/plugins/{name}/$(basename $JAR)
+    [ "$JAR" -ef "$DEST_JAR" ] || mv $JAR $DEST_JAR
+    echo "$PLUGIN_VERSION" > bazel-genfiles/plugins/{name}/$(basename $JAR-version)
+done