Deploy SNAPSHOTs to Maven

One of the common problems of developing a plugin
for Gerrit is to retrieve API dependencies from Maven
for a non-release version of Gerrit.

Push from now on all the successful SNAPSHOT builds
to Maven, so that plugin developers are not required anymore
to clone and build Gerrit API locally.

Change-Id: Ie253f3e1e11b22850c96efbc8482e9f5d2b64872
diff --git a/jenkins/gerrit-buck-bazel-template.yaml b/jenkins/gerrit-buck-bazel-template.yaml
index 7f974aa..6209908 100644
--- a/jenkins/gerrit-buck-bazel-template.yaml
+++ b/jenkins/gerrit-buck-bazel-template.yaml
@@ -129,6 +129,8 @@
          !include-raw: gerrit-bazel-test.sh
       - shell:
          !include-raw-escape: gerrit-bazel-cat-test-log.sh
+      - shell:
+         !include-raw: gerrit-deploy-api.sh
     publishers:
       - archive:
          artifacts: >
diff --git a/jenkins/gerrit-deploy-api.sh b/jenkins/gerrit-deploy-api.sh
new file mode 100644
index 0000000..2af1659
--- /dev/null
+++ b/jenkins/gerrit-deploy-api.sh
@@ -0,0 +1,11 @@
+#!/bin/bash -e
+
+if [ -f ~/.m2/settings.xml ]
+then
+  if grep -q sonatype-nexus-staging ~/.m2/settings.xml
+  then
+    echo "Deploying artifacts to Maven ..."
+    cd gerrit && ./tools/maven/api.sh deploy
+    echo "DONE"
+  fi
+fi