Revert "Revert "Bazel: Activate RBE configuration on GCP""

This reverts commit 1d2ae4f7f548a9645ba050ec32a90b5a50010167.

Setting multiple properties in jenkins job builder messed up and the
RBE build property wasn't set correctly.

In new version of this change RBE project name is placed in the jenkins
script.

Change-Id: I0b01cf574cccf27507fea46a4deb78f4ae35b537
diff --git a/jenkins/checker_definitions.txt b/jenkins/checker_definitions.txt
index 37dd066..f2cbf79 100644
--- a/jenkins/checker_definitions.txt
+++ b/jenkins/checker_definitions.txt
@@ -1,6 +1,17 @@
 POST /plugins/checks/checkers/ HTTP/1.0
   Content-Type: application/json; charset=UTF-8
   {
+    "uuid": "gerritforge:rbe-a6a0e4682515f3521897c5f950d1394f4619d928",
+    "name": "RBE Build/Tests",
+    "description": "Builds the code base and executes unit/integration tests on RBE",
+    "repository": "gerrit",
+    "query": "branch:master",
+    "blocking": []
+  }
+
+POST /plugins/checks/checkers/ HTTP/1.0
+  Content-Type: application/json; charset=UTF-8
+  {
     "uuid": "gerritforge:notedb-a6a0e4682515f3521897c5f950d1394f4619d928",
     "name": "Build/Tests",
     "description": "Builds the code base and executes unit/integration tests",
diff --git a/jenkins/gerrit-bazel-build.sh b/jenkins/gerrit-bazel-build.sh
index 39049e4..d02c40b 100644
--- a/jenkins/gerrit-bazel-build.sh
+++ b/jenkins/gerrit-bazel-build.sh
@@ -4,6 +4,9 @@
 
 cd gerrit
 
+echo "Build with mode=$MODE"
+echo '----------------------------------------------'
+
 if git show --diff-filter=AM --name-only --pretty="" HEAD | grep -q .bazelversion
 then
   export BAZEL_OPTS=""
@@ -11,6 +14,14 @@
 
 java -fullversion
 bazelisk version
-bazelisk build $BAZEL_OPTS plugins:core release api
-tools/maven/api.sh install
-tools/eclipse/project.py --bazel bazelisk
+
+if [[ "$MODE" == *"rbe"* ]]
+then
+    # TODO(davido): Figure out why javadoc part of api-rule doesn't work on RBE.
+    # See: https://github.com/bazelbuild/bazel/issues/12765 for more background.
+  bazelisk build --config=remote --remote_instance_name=projects/api-project-164060093628/instances/default_instance plugins:core release api-skip-javadoc
+else
+  bazelisk build $BAZEL_OPTS plugins:core release api
+  tools/maven/api.sh install
+  tools/eclipse/project.py --bazel bazelisk
+fi
diff --git a/jenkins/gerrit-bazel-verifier-test.sh b/jenkins/gerrit-bazel-verifier-test.sh
index 8851b4d..102b229 100755
--- a/jenkins/gerrit-bazel-verifier-test.sh
+++ b/jenkins/gerrit-bazel-verifier-test.sh
@@ -7,7 +7,14 @@
 echo "Test with mode=$MODE"
 echo '----------------------------------------------'
 
-case $TARGET_BRANCH in
+case $TARGET_BRANCH$MODE in
+  masterrbe)
+    TEST_TAG_FILTER="-flaky,-elastic,-git-protocol-v2"
+    BAZEL_OPTS="--config=remote --remote_instance_name=projects/api-project-164060093628/instances/default_instance"
+    ;;
+  masterNoteDb)
+    TEST_TAG_FILTER="-flaky,elastic,git-protocol-v2"
+    ;;
   stable-2.*)
     TEST_TAG_FILTER="-flaky,-elastic"
     ;;
@@ -30,7 +37,7 @@
 if [[ "$MODE" == *"reviewdb"* ]]
 then
   GERRIT_NOTEDB="--test_env=GERRIT_NOTEDB=OFF"
-  bazelisk test $BAZEL_OPTS //...
+  bazelisk test $GERRIT_NOTEDB $BAZEL_OPTS //...
 fi
 
 if [[ "$MODE" == *"notedb"* ]]
@@ -39,6 +46,11 @@
   bazelisk test $GERRIT_NOTEDB $BAZEL_OPTS //...
 fi
 
+if [[ "$MODE" == *"rbe"* ]]
+then
+  bazelisk test $BAZEL_OPTS //...
+fi
+
 if [[ "$MODE" == *"polygerrit"* ]]
 then
 
diff --git a/jenkins/gerrit-verifier.yaml b/jenkins/gerrit-verifier.yaml
index 150738c..81b5739 100644
--- a/jenkins/gerrit-verifier.yaml
+++ b/jenkins/gerrit-verifier.yaml
@@ -64,6 +64,7 @@
             - reviewdb
             - notedb
             - polygerrit
+            - rbe
           description: 'Type of verification to execute'
     properties:
       - authorization:
diff --git a/vars/gerritPipeline.groovy b/vars/gerritPipeline.groovy
index 6f25cd5..b5711e8 100644
--- a/vars/gerritPipeline.groovy
+++ b/vars/gerritPipeline.groovy
@@ -130,7 +130,9 @@
 
 def collectBuildModes() {
     Builds.modes = []
-    if (env.GERRIT_BRANCH ==~ /stable-3.*/ || env.GERRIT_BRANCH == "master") {
+    if (env.GERRIT_BRANCH == "master") {
+        Builds.modes = ["notedb", "rbe"]
+    } else if (env.GERRIT_BRANCH ==~ /stable-3.*/) {
         Builds.modes = ["notedb"]
     } else if (env.GERRIT_BRANCH == "stable-2.16") {
         Builds.modes = ["notedb", "reviewdb"]