Add configuration files for each job

default.json will be used for a job without a specific json configuration file.
Ideally those configuration file would live next to the repository they are used
to describe the tests we need to run for the repository.

Change-Id: I4fa2d31836ddd70f23b08a717e3cb881b5a8d9d1
diff --git a/jenkins/build_defs/BUILD b/jenkins/build_defs/BUILD
index 5e3624a..310d664 100644
--- a/jenkins/build_defs/BUILD
+++ b/jenkins/build_defs/BUILD
@@ -1,4 +1,11 @@
+load("//jenkins/lib:def.bzl", "bazel_job_configuration_test")
+
 exports_files(glob([
     "github-jobs*.tpl",
     "folder.xml",
 ]))
+
+bazel_job_configuration_test(
+    name = "default-config-test",
+    configs = ["default.json"],
+)
diff --git a/jenkins/build_defs/default.json b/jenkins/build_defs/default.json
new file mode 100644
index 0000000..9f9fb5b
--- /dev/null
+++ b/jenkins/build_defs/default.json
@@ -0,0 +1,19 @@
+// This is a relaxed JSON format, you can have comments in it.
+// This is a list of configuration for the job that does not specify a configuration.
+[
+    {
+        "configurations": [
+            {
+                "variation": "",
+                "configurations": [
+                    {"node": "linux-x86_64"},
+                    {"node": "ubuntu_16.04-x86_64"},
+                    {"node": "darwin-x86_64"}
+                ]
+            }
+        ],
+        "parameters": {
+            "test_opts": ["--build_tests_only"]
+        }
+    }
+]
diff --git a/jenkins/jobs/configs/bazel-docker-tests.json b/jenkins/jobs/configs/bazel-docker-tests.json
new file mode 100644
index 0000000..85bbd82
--- /dev/null
+++ b/jenkins/jobs/configs/bazel-docker-tests.json
@@ -0,0 +1,10 @@
+[
+    {
+        "node": "docker",
+        "variation": "",
+        "parameters": {
+            "targets": [],
+            "tests": ["//tools/cpp/test/..."]
+        }
+    }
+]
diff --git a/jenkins/jobs/configs/bazel-tests.json b/jenkins/jobs/configs/bazel-tests.json
new file mode 100644
index 0000000..cce8206
--- /dev/null
+++ b/jenkins/jobs/configs/bazel-tests.json
@@ -0,0 +1,129 @@
+// This is a relaxed JSON format, you can have comment in it.
+// This is a list of configuration for the bazel-tests job.
+[
+    {
+        // This is a configuration that have 3 subconfigurations: linux, ubuntu and darwin
+        // Each of those configurations have 4 bazel variations: HEAD, HEAD-jdk7, latest,
+        // and latest-jdk7
+        // A job configuration special keys are:
+        //   node -> indicate a node label to run the configuration on
+        //   variation -> an extra content to the bazel version
+        "configurations": [
+            {
+                "node": "linux-x86_64",
+                "configurations": [
+                    {"variation": ""},
+                    {"variation": "-jdk7"}
+                ]
+            },
+            {
+                "node": "ubuntu_16.04-x86_64",
+                "configurations": [
+                    {"variation": ""},
+                    {"variation": "-jdk7"}
+                ]
+            }
+        ],
+        // And specify the parameters for these configurations, which can be:
+        //   configure: list of configuration step to run before bazel
+        //   tests: tests to execute, default to ["//..."]
+        //   targets: targets to build, default to ["//..."]
+        //   test_tag_filters: tag to filter test (-noci and -manual are automatically added)
+        //   build_tag_filters: tag to filter target to build
+        //   test_opts: test options
+        //   build_opts: build options
+        "parameters": {
+            "configure": [
+                "echo >>WORKSPACE",
+                "cat >>WORKSPACE <<EOF",
+                "android_sdk_repository(",
+                "    name = \"androidsdk\",",
+                "    path = \"${ANDROID_SDK_PATH}\",",
+                ")",
+                "android_ndk_repository(",
+                "    name = \"androidndk\",",
+                "    path = \"${ANDROID_NDK_PATH}\",",
+                ")",
+                "EOF"
+          ],
+            "test_opts": ["-k", "--build_tests_only"],
+            "tests": [
+                "//scripts/...",
+                "//src/...",
+                "//third_party/ijar/...",
+                "//tools/android/..."
+            ],
+            "targets": []
+        }
+    }, {
+        "node": "darwin-x86_64",
+        "configurations": [
+            {"variation": ""},
+            {"variation": "-jdk7"}
+        ],
+        "parameters": {
+            "configure": [
+                "echo >>WORKSPACE",
+                "cat >>WORKSPACE <<EOF",
+                "android_sdk_repository(",
+                "    name = \"androidsdk\",",
+                "    path = \"${ANDROID_SDK_PATH}\",",
+              ")",
+                "android_ndk_repository(",
+                "    name = \"androidndk\",",
+                "    path = \"${ANDROID_NDK_PATH}\",",
+                ")",
+                "EOF"
+            ],
+            "build_opts": ["--define IPHONE_SDK=1"],
+            "test_opts": ["-k", "--build_tests_only"],
+            "tests": [
+                "//scripts/...",
+                "//src/...",
+                "//third_party/ijar/...",
+                "//tools/android/..."
+            ],
+            "targets": []
+        }
+    }, {
+        "toolchain": "msvc",
+        "configurations": [{
+            // TODO(dmarting): MSVC is a misnommer, it should have been called win32
+            // (for win32 native binary).
+            // TODO(dmarting): really MSVC/Win32 should be a bazel variation, not part of
+            // the node.
+            "node": "windows-msvc-x86_64",
+            "variation": ""
+        }, {
+            "node": "windows-x86_64",
+            "variation": ""
+        }],
+        "parameters": {
+            "test_opts": ["-k", "--build_tests_only"],
+            "tests": [
+                "//src/test/java/...",
+                "//src/test/cpp/...",
+                "//src/test/native:all_tests"
+            ],
+            "targets": ["//src:bazel"]
+        }
+    }, {
+        "toolchain": "msys",
+        "configurations": [{
+            // TODO(dmarting): MSVC is a misnommer, it should have been called win32
+            // (for win32 native binary).
+            // TODO(dmarting): really MSVC/Win32 should be a bazel variation, not part of
+            // the node.
+            "node": "windows-msvc-x86_64",
+            "variation": ""
+        }, {
+            "node": "windows-x86_64",
+            "variation": ""
+        }],
+        "parameters": {
+            "test_opts": ["-k", "--build_tests_only"],
+            "tests": ["//src/tst/shell/bazel:bazel_windows_example_test"],
+            "targets": []
+        }
+    }
+]
diff --git a/jenkins/jobs/configs/buildifier.json b/jenkins/jobs/configs/buildifier.json
new file mode 100644
index 0000000..72dac2b
--- /dev/null
+++ b/jenkins/jobs/configs/buildifier.json
@@ -0,0 +1,18 @@
+[
+    {
+        "configurations": [
+            {
+                "variation": "",
+                "configurations": [
+                    {"node": "linux-x86_64"},
+                    {"node": "ubuntu_16.04-x86_64"},
+                    {"node": "darwin-x86_64"}
+                ]
+            }
+        ],
+        "parameters": {
+            "targets": [],
+            "tests": [":tests"]
+        }
+    }
+]
diff --git a/jenkins/jobs/configs/continuous-integration.json b/jenkins/jobs/configs/continuous-integration.json
new file mode 100644
index 0000000..6e699f2
--- /dev/null
+++ b/jenkins/jobs/configs/continuous-integration.json
@@ -0,0 +1,6 @@
+[
+    {
+        "node": "docker",
+        "variation": ""
+    }
+]
diff --git a/jenkins/jobs/configs/gerrit.json b/jenkins/jobs/configs/gerrit.json
new file mode 100644
index 0000000..5870874
--- /dev/null
+++ b/jenkins/jobs/configs/gerrit.json
@@ -0,0 +1,18 @@
+[
+    {
+        "configurations": [
+            {
+                "variation": "",
+                "configurations": [
+                    {"node": "linux-x86_64"},
+                    {"node": "ubuntu_16.04-x86_64"},
+                    {"node": "darwin-x86_64"}
+                ]
+            }
+        ],
+        "parameters": {
+            "tests": ["//..."],
+            "targets": ["//:release"]
+        }
+    }
+]
diff --git a/jenkins/jobs/configs/intellij.json b/jenkins/jobs/configs/intellij.json
new file mode 100644
index 0000000..6fdc7bd
--- /dev/null
+++ b/jenkins/jobs/configs/intellij.json
@@ -0,0 +1,60 @@
+[
+    {
+        "product": "intellij",
+        "configurations": [
+            {
+                "variation": "",
+                "configurations": [
+                    {"node": "linux-x86_64"},
+                    {"node": "ubuntu_16.04-x86_64"},
+                    {"node": "darwin-x86_64"}
+                ]
+            }
+        ],
+        "parameters": {
+            "targets": ["ijwb:ijwb_bazel"],
+            "test_opts": ["--define=ij_product=intellij-latest"],
+            "build_opts": ["--define=ij_product=intellij-latest"],
+            "tests": [":ijwb_tests"]
+        }
+    },
+    {
+        "product": "clion",
+        "configurations": [
+            {
+                "variation": "",
+                "configurations": [
+                    {"node": "linux-x86_64"},
+                    {"node": "ubuntu_16.04-x86_64"},
+                    {"node": "darwin-x86_64"}
+                ]
+            }
+        ],
+        "parameters": {
+            "targets": ["clwb:clwb_bazel"],
+            "test_opts": ["--define=ij_product=clion-latest"],
+            "build_opts": ["--define=ij_product=clion-latest"],
+            "tests": [":clwb_tests"]
+        }
+    }//,
+    // TODO(dmarting): Reenable android-studio when upstream is fixed
+    // {
+    //     "name": "android-studio",
+    //     "configurations": [
+    //         {
+    //             "variation": "",
+    //             "configurations": [
+    //                 {"node": "linux-x86_64"},
+    //                 {"node": "ubuntu_16.04-x86_64"},
+    //                 {"node": "darwin-x86_64"}
+    //             ]
+    //         }
+    //     ],
+    //     "parameters": {
+    //         "targets": ["aswb:aswb_bazel"],
+    //         "test_opts": ["--define=ij_product=android-studio-latest"],
+    //         "build_opts": ["--define=ij_product=android-studio-latest"],
+    //         "tests": [":aswb_tests"]
+    //     }
+    // }
+]
diff --git a/jenkins/jobs/configs/protobuf.json b/jenkins/jobs/configs/protobuf.json
new file mode 100644
index 0000000..6c09c63
--- /dev/null
+++ b/jenkins/jobs/configs/protobuf.json
@@ -0,0 +1,19 @@
+[
+    {
+        "configurations": [
+            {
+                "variation": "",
+                "configurations": [
+                    {"node": "linux-x86_64"},
+                    {"node": "ubuntu_16.04-x86_64"},
+                    {"node": "darwin-x86_64"}
+                ]
+            }
+        ],
+        "parameters": {
+            "targets": [],
+            // on Linux protobuf tries to build objc target so filter by test only
+            "tests": ["//:all"]
+        }
+    }
+]
diff --git a/jenkins/jobs/configs/re2.json b/jenkins/jobs/configs/re2.json
new file mode 100644
index 0000000..9b392f9
--- /dev/null
+++ b/jenkins/jobs/configs/re2.json
@@ -0,0 +1,18 @@
+[
+    {
+        "configurations": [
+            {
+                "variation": "",
+                "configurations": [
+                    {"node": "linux-x86_64"},
+                    {"node": "ubuntu_16.04-x86_64"},
+                    {"node": "darwin-x86_64"}
+                ]
+            }
+        ],
+        "parameters": {
+            "targets": [],
+            "tests": ["//:all"]
+        }
+    }
+]
diff --git a/jenkins/jobs/configs/rules_dotnet.json b/jenkins/jobs/configs/rules_dotnet.json
new file mode 100644
index 0000000..cebef9c
--- /dev/null
+++ b/jenkins/jobs/configs/rules_dotnet.json
@@ -0,0 +1,15 @@
+[
+    {
+        "configurations": [
+            {
+                "variation": "",
+                "configurations": [
+                    // rules_dotnet is disabled on Linux until bazelbuild/rules_dotnet#13 is fixed.
+                    // {"node": "linux-x86_64"},
+                    // {"node": "ubuntu_16.04-x86_64"},
+                    {"node": "darwin-x86_64"}
+                ]
+            }
+        ]
+    }
+]
diff --git a/jenkins/jobs/configs/rules_jsonnet.json b/jenkins/jobs/configs/rules_jsonnet.json
new file mode 100644
index 0000000..0ae4c0e
--- /dev/null
+++ b/jenkins/jobs/configs/rules_jsonnet.json
@@ -0,0 +1,18 @@
+[
+    {
+        "configurations": [
+            {
+                "variation": "",
+                "configurations": [
+                    {"node": "linux-x86_64"},
+                    {"node": "ubuntu_16.04-x86_64"},
+                    {"node": "darwin-x86_64"}
+                ]
+            }
+        ],
+        "parameters": {
+            "targets": ["//...", "@examples//..."],
+            "tests": ["//...", "@examples//..."]
+        }
+    }
+]
diff --git a/jenkins/jobs/configs/rules_rust.json b/jenkins/jobs/configs/rules_rust.json
new file mode 100644
index 0000000..0ae4c0e
--- /dev/null
+++ b/jenkins/jobs/configs/rules_rust.json
@@ -0,0 +1,18 @@
+[
+    {
+        "configurations": [
+            {
+                "variation": "",
+                "configurations": [
+                    {"node": "linux-x86_64"},
+                    {"node": "ubuntu_16.04-x86_64"},
+                    {"node": "darwin-x86_64"}
+                ]
+            }
+        ],
+        "parameters": {
+            "targets": ["//...", "@examples//..."],
+            "tests": ["//...", "@examples//..."]
+        }
+    }
+]
diff --git a/jenkins/jobs/configs/rules_scala.json b/jenkins/jobs/configs/rules_scala.json
new file mode 100644
index 0000000..246f80d
--- /dev/null
+++ b/jenkins/jobs/configs/rules_scala.json
@@ -0,0 +1,18 @@
+[
+    {
+        "configurations": [
+            {
+                "variation": "",
+                "configurations": [
+                    {"node": "linux-x86_64"},
+                    {"node": "ubuntu_16.04-x86_64"},
+                    {"node": "darwin-x86_64"}
+                ]
+            }
+        ],
+        "parameters": {
+            "targets": ["//test/..."],
+            "tests": ["//test/..."]
+        }
+    }
+]
diff --git a/jenkins/jobs/configs/tensorflow.json b/jenkins/jobs/configs/tensorflow.json
new file mode 100644
index 0000000..54987b7
--- /dev/null
+++ b/jenkins/jobs/configs/tensorflow.json
@@ -0,0 +1,39 @@
+[
+    {
+        "configurations": [
+            {
+                "variation": "",
+                "configurations": [
+                    {"node": "linux-x86_64"},
+                    {"node": "ubuntu_16.04-x86_64"}
+                ]
+            }
+        ],
+        "parameters": {
+            "configure": [
+                "echo 'import %workspace%/.bazelrc' >>bazel.bazelrc",
+                "./tensorflow/tools/ci_build/builds/configured CPU"
+            ],
+            "test_opts": ["--test_timeout=1800"],
+            "build_opts": ["-c opt"],
+            "tests": ["filter(\":(lib|platform)_.*\", kind(test, //tensorflow/core:all))"],
+            "targets": ["//tensorflow/tools/pip_package:build_pip_package"]
+        }
+    }, {
+        "toolchain": "msvc",
+        "configurations": [{
+            "variation": "",
+            "configurations": [{"node": "windows-msvc-x86_64", "node": "windows-x86_64"}]
+        }],
+        "parameters": {
+            // TODO(dmarting): this is terrible, can we actually call Bazel?
+            "tests": [],
+            "targets": [],
+            "configure": [
+                "del c:\\tools\\msys64\\usr\\bin\\bazel.exe",
+                "copy %BAZEL% c:\\tools\\msys64\\usr\\bin\\bazel.exe",
+                ".\\tensorflow\\tools\\ci_build\\windows\\cpu\\pip\\run.bat"
+            ],
+        }
+    }
+]
diff --git a/jenkins/jobs/configs/tensorflow_serving.json b/jenkins/jobs/configs/tensorflow_serving.json
new file mode 100644
index 0000000..1f0db2f
--- /dev/null
+++ b/jenkins/jobs/configs/tensorflow_serving.json
@@ -0,0 +1,20 @@
+[
+    {
+        "configurations": [
+            {
+                "variation": "",
+                "configurations": [
+                    {"node": "linux-x86_64"},
+                    {"node": "ubuntu_16.04-x86_64"}
+                ]
+            }
+        ],
+        "parameters": {
+            "configure": [
+                "(cd tensorflow && ./tensorflow/tools/ci_build/builds/configured CPU)"
+            ],
+            "tests": ["tensorflow_serving/..."],
+            "targets": []
+        }
+    }
+]
diff --git a/jenkins/jobs/configs/tf_models_syntaxnet.json b/jenkins/jobs/configs/tf_models_syntaxnet.json
new file mode 100644
index 0000000..5360ea1
--- /dev/null
+++ b/jenkins/jobs/configs/tf_models_syntaxnet.json
@@ -0,0 +1,20 @@
+[
+    {
+        "configurations": [
+            {
+                "variation": "",
+                "configurations": [
+                    {"node": "linux-x86_64"},
+                    {"node": "ubuntu_16.04-x86_64"}
+                ]
+            }
+        ],
+        "parameters": {
+            "configure": [
+                "(cd tensorflow && ./tensorflow/tools/ci_build/builds/configured CPU)"
+            ],
+            "tests": ["syntaxnet/...", "util/utf8/..."],
+            "targets": []
+        }
+    }
+]
diff --git a/jenkins/jobs/configs/tutorial.json b/jenkins/jobs/configs/tutorial.json
new file mode 100644
index 0000000..6fd4021
--- /dev/null
+++ b/jenkins/jobs/configs/tutorial.json
@@ -0,0 +1,31 @@
+[
+    {
+        "configurations": [
+            {
+                "variation": "",
+                "configurations": [
+                    {"node": "linux-x86_64"},
+                    {"node": "ubuntu_16.04-x86_64"},
+                    {"node": "darwin-x86_64"}
+                ]
+            }
+        ],
+        "parameters": {
+            "configure": [
+                "echo >>WORKSPACE",
+                "cat >>WORKSPACE <<EOF",
+                "android_sdk_repository(",
+                "    name = \"androidsdk\",",
+                "    path = \"${ANDROID_SDK_PATH}\",",
+                ")",
+                "android_ndk_repository(",
+                "    name = \"androidndk\",",
+                "    path = \"${ANDROID_NDK_PATH}\",",
+                ")",
+                "EOF"
+            ],
+            "targets": ["//:all"],
+            "tests": []
+        }
+    }
+]