Build Analytics ETL on Gerrit CI

Spark Analytics ETL is one of the key components
of the Gerrit Analytics OpenSource project.
Build the Spark Job on Gerrit CI and simplyfy people's
life by having a binary to download and run on their setups.

Change-Id: I4425aae5afaf89c44b130b50d42fb8146a92410e
diff --git a/jenkins/gerrit-app-analytics-etl.yaml b/jenkins/gerrit-app-analytics-etl.yaml
new file mode 100644
index 0000000..9c48c24
--- /dev/null
+++ b/jenkins/gerrit-app-analytics-etl.yaml
@@ -0,0 +1,54 @@
+- job-template:
+    name: 'app-{name}-sbt-{branch}'
+    description: "App {name} {branch} branch build with Sbt"
+    node: sbt
+    targets: compile test assembly
+    wrappers:
+      - timeout:
+          timeout: 30
+          fail: true
+      - timestamps
+      - raw:
+          xml: <jenkins.plugins.logstash.LogstashBuildWrapper plugin="logstash@1.2.0"/>
+    properties:
+       - build-discarder:
+           days-to-keep: 20
+           artifact-days-to-keep: 20
+       - authorization:
+           anonymous:
+             - job-discover
+             - job-read
+             - job-extended-read
+    scm:
+      - git:
+         remotes:
+           - origin:
+               url: https://gerrit.googlesource.com/apps/{name}
+         branches:
+           - origin/{branch}
+         submodule:
+           recursive: true
+         skip-tag: true
+
+    triggers:
+      - pollscm:
+          cron: 'H/50 * * * *'
+
+    builders:
+      - shell:
+         !include-raw: gerrit-sbt-build-app.sh
+    publishers:
+      - archive:
+         artifacts: '**/target/**/*{name}*.jar*,**/target/**/*{name}*.json'
+
+    wrappers:
+      - raw:
+          xml: <jenkins.plugins.logstash.LogstashBuildWrapper plugin="logstash@1.2.0"/>
+
+- project:
+    name: analytics-etl
+    jobs:
+      - 'app-{name}-sbt-{branch}':
+          branch:
+            - master
+
diff --git a/jenkins/gerrit-sbt-build-app.sh b/jenkins/gerrit-sbt-build-app.sh
new file mode 100644
index 0000000..6ceb8a9
--- /dev/null
+++ b/jenkins/gerrit-sbt-build-app.sh
@@ -0,0 +1,17 @@
+#!/bin/bash -e
+
+sbt -no-colors {targets}
+
+# Extract version information
+JARS=$(find . -name '{name}*jar')
+for jar in $JARS
+do
+  VERSION=$(git describe  --always origin/{branch})
+  echo -e "Implementation-Version: $VERSION" > MANIFEST.MF
+  jar ufm $jar MANIFEST.MF && rm MANIFEST.MF
+
+  echo "$VERSION" > $jar-version
+
+  curl -L https://gerrit-review.googlesource.com/projects/apps%2F{name}/config | \
+     tail -n +2 > $(dirname $jar)/$(basename $jar .jar).json
+done