Gitblit plugin build with Bazel

Change-Id: I0dfbd4002e4e439cd5f7d10beadb81d0bad4b878
diff --git a/jenkins/gerrit-buck-plugin-gitblit.yaml b/jenkins/gerrit-buck-bazel-plugin-gitblit.yaml
similarity index 61%
rename from jenkins/gerrit-buck-plugin-gitblit.yaml
rename to jenkins/gerrit-buck-bazel-plugin-gitblit.yaml
index 97402cb..210a0a4 100644
--- a/jenkins/gerrit-buck-plugin-gitblit.yaml
+++ b/jenkins/gerrit-buck-bazel-plugin-gitblit.yaml
@@ -1,5 +1,5 @@
-- job-template:
-    name: 'plugin-gitblit-{branch}'
+- defaults:
+    name: 'plugin-gitblit'
     description: "GitBlit plugin {branch} branch build with BUCK\n"
     defaults: buck-plugin
     wrappers:
@@ -38,6 +38,10 @@
       - pollscm:
           cron: 'H/50 * * * *'
 
+- job-template:
+    name: 'plugin-gitblit-{branch}'
+    description: "GitBlit plugin {branch} branch build with BUCK\n"
+    defaults: plugin-gitblit
     builders:
       - shell:
          !include-raw: gitblit-ant-build.sh
@@ -47,13 +51,32 @@
       - archive:
          artifacts: 'buck-out/gen/plugins/gitblit/*gitblit*.jar*'
 
+- job-template:
+    name: 'plugin-gitblit-bazel-{branch}'
+    description: "GitBlit plugin {branch} branch build with Bazel\n"
+    defaults: plugin-gitblit
+    builders:
+      - shell:
+         !include-raw: gitblit-ant-build.sh
+      - shell:
+         !include-raw: gerrit-bazel-build-plugin.sh
+    publishers:
+      - archive:
+         artifacts: 'bazel-genfiles/plugins/gitblit/*gitblit*.jar*'
+
+
 - project:
     name: gitblit
-    branch:
-      - master
-      - stable-2.12
-      - stable-2.11
-      - stable-2.10
     jobs:
-      - 'plugin-gitblit-{branch}'
+      - 'plugin-gitblit-{branch}':
+          targets: plugins/gitblit
+          branch:
+            - stable-2.13
+            - stable-2.12
+            - stable-2.11
+            - stable-2.10
+      - 'plugin-gitblit-bazel-{branch}':
+          targets: plugins/gitblit
+          branch:
+            - master
 
diff --git a/jenkins/gitblit-ant-build.sh b/jenkins/gitblit-ant-build.sh
index 4302053..a7453cc 100755
--- a/jenkins/gitblit-ant-build.sh
+++ b/jenkins/gitblit-ant-build.sh
@@ -1,7 +1,27 @@
 #!/bin/bash -ex
 
 git checkout origin/{branch}
-GITBLIT_TAG=$(expr "`grep com.gitblit lib/BUCK`" : '[^:]*:[^:]*:\([0-9\.]*\)')
+if [ -f BUILD ]
+then
+  GITBLIT_LINE=$(grep com.gitblit external_plugin_deps.bzl)
+  if expr "$GITBLIT_LINE" : '.*[0-9\.]*-SNAPSHOT.*'
+  then
+    GITBLIT_REF=refs/heads/master
+  else
+    GITBLIT_REF=refs/tags/v$(expr "$GITBLIT_LINE" : '[^:]*:[^:]*:\([0-9\.]*\)')
+  fi
+else
+  GITBLIT_REF=refs/tags/v$(expr "`grep com.gitblit lib/BUCK`" : '[^:]*:[^:]*:\([0-9\.]*\)')
+fi
 
-git fetch gitblit refs/tags/v$GITBLIT_TAG && git checkout FETCH_HEAD
+git fetch gitblit $GITBLIT_REF && git checkout FETCH_HEAD
+
+# Apply PR#1168 for Lucene compatibility with Gerrit master
+if [ "$GITBLIT_REF" == "refs/heads/master" ]
+then
+  git config user.name "Gerrit CI"
+  git config user.email "jenkins@gerritforge.com"
+  git fetch gitblit refs/pull/1168/head && git merge --no-edit FETCH_HEAD
+fi
+
 ant -DresourceFolderPrefix=static installMaven