Run basic integration tests of FreeBSD

Test at least //src/test/shell/integration/... on FreeBSD. Note that
the code cannot be used as is; instead we have to replay the
USES=shebangfix of the port. First step for #54.

Change-Id: I1ec52a0163000f034ef479ba0502697752b198ed
diff --git a/jenkins/jobs/configs/bazel-tests.json b/jenkins/jobs/configs/bazel-tests.json
index 7c1a97a..4116595 100644
--- a/jenkins/jobs/configs/bazel-tests.json
+++ b/jenkins/jobs/configs/bazel-tests.json
@@ -47,6 +47,35 @@
             "targets": []
         }
     }, {
+        "configurations": [
+            {
+                "node": "freebsd-11",
+                "variation": ""
+            },
+            {
+                "node": "freebsd-12",
+                "variation": ""
+            }
+        ],
+        "parameters": {
+            // As configure step, we redo the USES=shebangfix of the devel/bazel
+            // port. In other words, we replace every #!-line calling bash by a
+            // line containing the correct path to bash on our test machines.
+            "configure": [
+                "find -E . -type f -iregex '.*(sh|txt|_stub|stub_.*|bazel|get_workspace_status|protobuf_support|_so)' \\",
+                "-exec sed -i '' \\",
+                "-e '1s|^\\#![[:space:]]*/bin/bash\\([[:space:]]\\)|\\#!/usr/local/bin/bash\\1|' \\",
+                "-e '1s|^\\#![[:space:]]*/bin/bash$|\\#!/usr/local/bin/bash|' \\",
+                "-e '1s|^\\#![[:space:]]*/usr/bin/env bash\\([[:space:]]\\)|\\#!/usr/local/bin/bash\\1|' \\",
+                "-e '1s|^\\#![[:space:]]*/usr/bin/env bash$|\\#!/usr/local/bin/bash|' \\",
+                "{} +"
+            ],
+            "tests": [
+                "//src/test/shell/integration/..."
+            ],
+            "targets": []
+        }
+    }, {
         "node": "darwin-x86_64",
         "variation": "",
         "parameters": {
diff --git a/jenkins/lib/src/build/bazel/ci/BazelUtils.groovy b/jenkins/lib/src/build/bazel/ci/BazelUtils.groovy
index 7d62da7..e10236f 100644
--- a/jenkins/lib/src/build/bazel/ci/BazelUtils.groovy
+++ b/jenkins/lib/src/build/bazel/ci/BazelUtils.groovy
@@ -195,7 +195,7 @@
   def testlogs(test_folder) {
     // JUnit test result does not look at test result if they are "old", copying them to a new
     // location, unique accross configurations.
-    def res = script.sh(script: """#!/bin/bash
+    def res = script.sh(script: """#!/bin/sh
 echo 'Copying test outputs and events file for archiving'
 rm -fr ${test_folder}
 mkdir -p ${test_folder}
diff --git a/jenkins/lib/vars/bazelJob.groovy b/jenkins/lib/vars/bazelJob.groovy
index d8ba531..e1541c1 100644
--- a/jenkins/lib/vars/bazelJob.groovy
+++ b/jenkins/lib/vars/bazelJob.groovy
@@ -55,7 +55,7 @@
       withEnv(["PATH=${new File(config.binary).parent}:${env.PATH}",
               "BAZEL=${config.binary}"]) {
         if (isUnix()) {
-          sh "#!/bin/bash -x\n${config.configuration.join('\n')}"
+          sh "#!/bin/sh -x\n${config.configuration.join('\n')}"
         } else {
           bat config.configuration.join('\n')
         }