Clean-up github jobs creation and simplify job lists

Some minor change:
  - Reorganized jenkins/jobs/BUILD which is the only
    file to modify now to add/reconfigure/remove a job
  - Changed the default org to be bazelbuild not google.

Tested: diffed generated XML files and tarball

Differences:
  - No longer generate XML for removed dash job
  - Correctly filter out continuous-integration for test system
  - Use regex to filter out the job view rather that maintain
    Skylark lists.

Change-Id: Ia10535e14611bdd517f7a346c643cc1049b72b08
diff --git a/jenkins/BUILD b/jenkins/BUILD
index a723788..fc72662 100644
--- a/jenkins/BUILD
+++ b/jenkins/BUILD
@@ -17,7 +17,6 @@
 # Configuration for our Jenkins instance
 load("@io_bazel_rules_docker//docker:docker.bzl", "docker_build")
 load("//jenkins/build_defs:jenkins.bzl", "jenkins_node", "jenkins_docker_build", "jenkins_job", "jenkins_nodes", "jenkins_node_names")
-load("//jenkins/jobs:jobs.bzl", "JOBS_SUBSTITUTIONS", "STAGING_JOBS_SUBSTITUTIONS")
 
 #
 # Nodes
@@ -285,7 +284,7 @@
     substitutions = {
         "SECURITY_CONFIG": SECURITY_CONFIG,
         "PUBLIC_JENKINS_URL": "http://ci.bazel.io/",
-    } + JOBS_SUBSTITUTIONS,
+    },
     tars = ["//jenkins/lib"],
     visibility = ["//visibility:public"],
 )
@@ -310,7 +309,7 @@
     substitutions = {
         "SECURITY_CONFIG": SECURITY_CONFIG,
         "PUBLIC_JENKINS_URL": "http://ci-staging.bazel.io/",
-    } + STAGING_JOBS_SUBSTITUTIONS,
+    },
     tars = ["//jenkins/lib"],
     visibility = ["//gcr:__pkg__"],
 )
@@ -331,7 +330,7 @@
     substitutions = {
         "SECURITY_CONFIG": "<useSecurity>false</useSecurity>",
         "PUBLIC_JENKINS_URL": "##ENV:JENKINS_SERVER##",
-    } + JOBS_SUBSTITUTIONS,
+    },
     tars = ["//jenkins/lib"],
 )
 
diff --git a/jenkins/build_defs/BUILD b/jenkins/build_defs/BUILD
index 6f2aa1e..c5d9fa2 100644
--- a/jenkins/build_defs/BUILD
+++ b/jenkins/build_defs/BUILD
@@ -1,7 +1,6 @@
 load("//jenkins/lib:def.bzl", "bazel_job_configuration_test")
 
 exports_files(glob([
-    "github-jobs*.tpl",
     "bazel-job*.tpl",
     "folder.xml",
     "default.json",
diff --git a/jenkins/build_defs/github-jobs.bat.tpl b/jenkins/build_defs/github-jobs.bat.tpl
deleted file mode 100644
index 1e7ba74..0000000
--- a/jenkins/build_defs/github-jobs.bat.tpl
+++ /dev/null
@@ -1,98 +0,0 @@
-:: Copyright 2016 The Bazel Authors. All rights reserved.
-::
-:: Licensed under the Apache License, Version 2.0 (the "License");
-:: you may not use this file except in compliance with the License.
-:: You may obtain a copy of the License at
-::
-::    http://www.apache.org/licenses/LICENSE-2.0
-::
-:: Unless required by applicable law or agreed to in writing, software
-:: distributed under the License is distributed on an "AS IS" BASIS,
-:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-:: See the License for the specific language governing permissions and
-:: limitations under the License.
-
-:: ATTENTION: This file is auto-generated from a template.
-:: See https://github.com/bazelbuild/continuous-integration/blob/master/jenkins/github-jobs.bat.tpl
-
-:: Batch script containing the main build phase for windows bazel_github_job-s
-@echo on
-set BAZEL_SH=c:\tools\msys64\usr\bin\bash.exe
-
-set BAZEL=c:\bazel_ci\installs\%BAZEL_VERSION%\bazel.exe
-set TMPDIR=c:\bazel_ci\temp
-
-:: Verify that BAZEL_VERSION is not empty and BAZEL exists.
-echo CI info: BAZEL_VERSION=(%BAZEL_VERSION%)
-echo CI info: BAZEL=(%BAZEL%)
-
-:: Check BAZEL_VERSION, it should be defined by Jenkins.
-if "%BAZEL_VERSION%" == "" (
-  echo ERROR: BAZEL_VERSION is empty
-  exit /b 1
-)
-
-:: Check if BAZEL exists.
-if exist "%BAZEL%" (
-  echo CI info: BAZEL binary found
-) else (
-  echo CI ERROR: BAZEL not found
-  exit /b 1
-)
-
-:: Remove MSYS path on Windows platform, the MSYS path
-:: was originally added by jenkins-slave-windows.ps1
-set PATH=%PATH:c:\tools\msys64\usr\bin;=%
-
-set ROOT=%cd%
-set BAZELRC=%ROOT%\.bazelrc
-del /q /f %BAZELRC%
-echo build {{ variables.BUILD_OPTS }} >> %BAZELRC%
-echo test {{ variables.TEST_OPTS }} >> %BAZELRC%
-echo test --test_tag_filters {{ variables.TEST_TAG_FILTERS }},-no_windows >> %BAZELRC%
-
-call:bazel version
-
-del /q /f .unstable
-
-:: Expand variables.WINDOWS_CONFIGURE
-{{ variables.WINDOWS_CONFIGURE }}
-
-:: Check variables.WINDOWS_BUILDS
-if not "{{ variables.WINDOWS_BUILDS }}" == "" (
-  call:bazel build --copt=-w --host_copt=-w {{ variables.WINDOWS_BUILDS }}
-)
-
-:: Check variables.WINDOWS_TESTS
-if not "{{ variables.WINDOWS_TESTS }}" == "" (
-  call:bazel test --copt=-w --host_copt=-w {{ variables.WINDOWS_TESTS }}
-)
-
-set MSYS_OPTION=--cpu=x64_windows_msys --host_cpu=x64_windows_msys
-
-:: Check variables.WINDOWS_BUILDS_MSYS
-if not "{{ variables.WINDOWS_BUILDS_MSYS }}" == "" (
-  call:bazel build %MSYS_OPTION% {{ variables.WINDOWS_BUILDS_MSYS }}
-)
-
-:: Check variables.WINDOWS_TESTS_MSYS
-if not "{{ variables.WINDOWS_TESTS_MSYS }}" == "" (
-  call:bazel test %MSYS_OPTION%  {{ variables.WINDOWS_TESTS_MSYS }}
-)
-
-exit %errorlevel%
-
-:bazel
-%BAZEL% --bazelrc=%BAZELRC% %*
-set retCode=%errorlevel%
-if %retCode%==3 (
-  :: Write 1 in the .unstable file so the following step in Jenkins
-  :: knows that it is a test failure.
-  echo 1 > %ROOT%\.unstable
-) else (
-  if not %retCode%==0 (
-    :: Else simply fail the job by exiting with a non-null return code.
-    exit %retCode%
-  )
-)
-exit /b 0
diff --git a/jenkins/build_defs/github-jobs.sh.tpl b/jenkins/build_defs/github-jobs.sh.tpl
deleted file mode 100644
index 4ca6ae2..0000000
--- a/jenkins/build_defs/github-jobs.sh.tpl
+++ /dev/null
@@ -1,81 +0,0 @@
-#!/bin/bash
-# Copyright 2016 The Bazel Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Shell script containing the main build phase for all bazel_github_job-s
-
-set -e
-set +x
-
-BAZEL=~/.bazel/${BAZEL_VERSION}/bin/bazel
-
-ROOT="${PWD}"
-
-TEST_TAG_FILTERS="{{ variables.TEST_TAG_FILTERS }}"
-BUILD_TAG_FILTERS=""
-
-cat >${ROOT}/bazel.bazelrc <<EOF
-import %workspace%/.bazelrc
-build {{ variables.BUILD_OPTS }}
-test {{ variables.TEST_OPTS }}
-test --test_tag_filters ${TEST_TAG_FILTERS}
-EOF
-
-if [[ ! -z "${BUILD_TAG_FILTERS}" ]];
-then
-  echo "build --build_tag_filters ${BUILD_TAG_FILTERS}" >> ${ROOT}/bazel.bazelrc
-fi
-
-if [[ "${PLATFORM_NAME}" =~ .*darwin.* ]] && \
-      xcodebuild -showsdks 2> /dev/null | grep -q '\-sdk iphonesimulator'; then
-  cat >>${ROOT}/bazel.bazelrc <<EOF
-build --define IPHONE_SDK=1
-EOF
-fi
-
-rm -f .unstable
-mkdir -p .bin
-cat <<EOF >.bin/bazel
-#!/bin/bash
-retCode=0
-${BAZEL} --bazelrc=${ROOT}/bazel.bazelrc "\$@" || retCode=\$?
-# Bazel returns 3 if there was test failures but no breakge
-if [[ "\$retCode" -eq "3" ]]; then
-  # Write 1 in the .unstable file so the following step in Jenkins
-  # know that it is a test failure.
-  echo 1 >"${ROOT}/.unstable"
-elif [[ "\$retCode" -ne "0" ]]; then
-  # Else simply fails the job by exiting with a non null return code
-  exit \$retCode
-fi
-EOF
-chmod +x .bin/bazel
-export PATH="${PWD}/.bin:${PATH}"
-
-cd {{ variables.WORKSPACE }}
-
-touch .bazelrc
-
-echo "==== bazel version ===="
-bazel version
-echo
-echo
-
-set -x
-
-{{ variables.CONFIGURE }}
-TESTS='{{ variables.TESTS }}'
-[ -z "${TESTS}" ] || TESTS="$(bazel query "tests(${TESTS})")"
-[ -z "{{ variables.BUILDS }}" ] || bazel build {{ variables.BUILDS }}
-[ -z "${TESTS}" ] || bazel test ${TESTS}
diff --git a/jenkins/build_defs/github-jobs.test-logs.bat.tpl b/jenkins/build_defs/github-jobs.test-logs.bat.tpl
deleted file mode 100644
index a92a4ec..0000000
--- a/jenkins/build_defs/github-jobs.test-logs.bat.tpl
+++ /dev/null
@@ -1,26 +0,0 @@
-:: Copyright 2016 The Bazel Authors. All rights reserved.
-::
-:: Licensed under the Apache License, Version 2.0 (the "License");
-:: you may not use this file except in compliance with the License.
-:: You may obtain a copy of the License at
-::
-::    http://www.apache.org/licenses/LICENSE-2.0
-::
-:: Unless required by applicable law or agreed to in writing, software
-:: distributed under the License is distributed on an "AS IS" BASIS,
-:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-:: See the License for the specific language governing permissions and
-:: limitations under the License.
-
-:: Batch to avoid failing bazel_github_job because of the absence of log files
-
-if NOT EXIST "{{ variables.WORKSPACE }}/bazel-testlogs/*" (
-  rmdir /q "{{ variables.WORKSPACE }}/bazel-testlogs"
-  md "{{ variables.WORKSPACE }}/bazel-testlogs"
-)
-
-set LOGFILE="{{ variables.WORKSPACE }}/bazel-testlogs/dummy.xml"
-echo ^<?xml version="1.0" encoding="UTF-8"?^> > %LOGFILE%
-echo ^<testsuites^> >> %LOGFILE%
-echo ^<testsuite name="dummy" tests="0" failures="0" errors="0"/^> >> %LOGFILE%
-echo ^</testsuites^> >> %LOGFILE%
diff --git a/jenkins/build_defs/github-jobs.test-logs.sh.tpl b/jenkins/build_defs/github-jobs.test-logs.sh.tpl
deleted file mode 100644
index 11d1ad1..0000000
--- a/jenkins/build_defs/github-jobs.test-logs.sh.tpl
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/bash
-# Copyright 2016 The Bazel Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Script to avoid failing bazel_github_job because of the absence of log files
-if [ ! -e "{{ variables.WORKSPACE }}/bazel-testlogs" ]; then
-  # Remove dangling symlink if present.
-  rm -f "{{ variables.WORKSPACE }}/bazel-testlogs"
-  mkdir -p "{{ variables.WORKSPACE }}/bazel-testlogs"
-fi
-cat <<EOF >{{ variables.WORKSPACE }}/bazel-testlogs/dummy.xml
-<?xml version="1.0" encoding="UTF-8"?>
-<testsuites>
-  <testsuite name="dummy" tests="0" failures="0" errors="0"/>
-</testsuites>
-EOF
diff --git a/jenkins/build_defs/github-jobs.xml.tpl b/jenkins/build_defs/github-jobs.xml.tpl
deleted file mode 100644
index 8b0f9e0..0000000
--- a/jenkins/build_defs/github-jobs.xml.tpl
+++ /dev/null
@@ -1,171 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<!--
-  Copyright 2015 The Bazel Authors. All rights reserved.
-
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-     http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-<matrix-project >
-  <actions/>
-  <description>Test the {{ variables.PROJECT_NAME }} project still build with Bazel at head and latest release.</description>
-  <keepDependencies>false</keepDependencies>
-  {% if variables.github == "True" %}
-  <properties>
-    <com.coravy.hudson.plugins.github.GithubProjectProperty >
-      <projectUrl>{{ variables.GITHUB_URL }}</projectUrl>
-    </com.coravy.hudson.plugins.github.GithubProjectProperty>
-  </properties>
-  {% endif %}
-  <scm class="hudson.plugins.git.GitSCM" >
-    <configVersion>2</configVersion>
-    <userRemoteConfigs>
-      <hudson.plugins.git.UserRemoteConfig>
-        <refspec>+refs/heads/*:refs/remotes/origin/*</refspec>
-        <url>{{ variables.GIT_URL }}</url>
-      </hudson.plugins.git.UserRemoteConfig>
-    </userRemoteConfigs>
-    <branches>
-      <hudson.plugins.git.BranchSpec>
-        <name>*/{{ variables.BRANCH }}</name>
-      </hudson.plugins.git.BranchSpec>
-    </branches>
-    <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
-    <submoduleCfg class="list"/>
-    <extensions>
-      <hudson.plugins.git.extensions.impl.CleanBeforeCheckout/>
-      <hudson.plugins.git.extensions.impl.AuthorInChangelog/>
-      <hudson.plugins.git.extensions.impl.SubmoduleOption>
-        <disableSubmodules>false</disableSubmodules>
-        <recursiveSubmodules>true</recursiveSubmodules>
-        <trackingSubmodules>false</trackingSubmodules>
-      </hudson.plugins.git.extensions.impl.SubmoduleOption>
-    </extensions>
-  </scm>
-  <quietPeriod>5</quietPeriod>
-  <canRoam>true</canRoam>
-  <disabled>{{ variables.disabled }}</disabled>
-  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
-  <blockBuildWhenUpstreamBuilding>true</blockBuildWhenUpstreamBuilding>
-  {% if variables.enable_trigger == "true" %}
-  <triggers>
-    <com.cloudbees.jenkins.GitHubPushTrigger >
-      <spec></spec>
-    </com.cloudbees.jenkins.GitHubPushTrigger>
-  </triggers>
-  {% endif %}
-  <concurrentBuild>false</concurrentBuild>
-  <axes>
-    <hudson.matrix.LabelAxis>
-      <name>PLATFORM_NAME</name>
-      <values>{% for v in variables.PLATFORMS.split("\n") %}<string>{{ v }}</string>{% endfor %}</values>
-    </hudson.matrix.LabelAxis>
-    <hudson.matrix.TextAxis>
-      <name>BAZEL_VERSION</name>
-       <values>{% for v in variables.BAZEL_VERSIONS.split("\n") %}<string>{{ v }}</string>{% endfor %}</values>
-    </hudson.matrix.TextAxis>
-  </axes>
-  <builders>
-    <org.jenkinsci.plugins.conditionalbuildstep.ConditionalBuilder plugin="conditional-buildstep@1.3.3">
-    <runner class="org.jenkins_ci.plugins.run_condition.BuildStepRunner$Fail" plugin="run-condition@1.0"/>
-    <runCondition class="org.jenkins_ci.plugins.run_condition.core.ExpressionCondition" plugin="run-condition@1.0">
-      <expression>^((?!windows).)*$</expression>
-      <label>${PLATFORM_NAME}</label>
-    </runCondition>
-    <conditionalbuilders>
-    <hudson.tasks.Shell>
-      <command>{{ imports['//jenkins/build_defs:github-jobs.sh.tpl'] }}</command>
-    </hudson.tasks.Shell>
-    <hudson.tasks.Shell>
-      <command>{{ imports['//jenkins/build_defs:github-jobs.test-logs.sh.tpl'] }}</command>
-    </hudson.tasks.Shell>
-    </conditionalbuilders>
-    </org.jenkinsci.plugins.conditionalbuildstep.ConditionalBuilder>
-
-    <org.jenkinsci.plugins.conditionalbuildstep.ConditionalBuilder plugin="conditional-buildstep@1.3.3">
-      <runner class="org.jenkins_ci.plugins.run_condition.BuildStepRunner$Fail" plugin="run-condition@1.0"/>
-      <runCondition class="org.jenkins_ci.plugins.run_condition.logic.And" plugin="run-condition@1.0">
-        <conditions>
-          <org.jenkins__ci.plugins.run__condition.logic.ConditionContainer>
-            <condition class="org.jenkins_ci.plugins.run_condition.core.ExpressionCondition">
-              <expression>windows.*</expression>
-              <label>${PLATFORM_NAME}</label>
-            </condition>
-          </org.jenkins__ci.plugins.run__condition.logic.ConditionContainer>
-        </conditions>
-      </runCondition>
-      <conditionalbuilders>
-        <hudson.tasks.BatchFile>
-          <command>{{ imports['//jenkins/build_defs:github-jobs.bat.tpl'] }}</command>
-        </hudson.tasks.BatchFile>
-        <hudson.tasks.BatchFile>
-          <command>{{ imports['//jenkins/build_defs:github-jobs.test-logs.bat.tpl'] }}</command>
-        </hudson.tasks.BatchFile>
-      </conditionalbuilders>
-    </org.jenkinsci.plugins.conditionalbuildstep.ConditionalBuilder>
-
-
-    <org.jenkinsci.plugins.conditionalbuildstep.singlestep.SingleConditionalBuilder >
-      <condition class="org.jenkins_ci.plugins.run_condition.core.FileExistsCondition" >
-        <file>.unstable</file>
-        <baseDir class="org.jenkins_ci.plugins.run_condition.common.BaseDirectory$Workspace"/>
-      </condition>
-      <buildStep class="org.jenkins_ci.plugins.fail_the_build.FixResultBuilder" >
-        <defaultResultName>UNSTABLE</defaultResultName>
-        <success></success>
-        <unstable></unstable>
-        <failure></failure>
-        <aborted></aborted>
-      </buildStep>
-      <runner class="org.jenkins_ci.plugins.run_condition.BuildStepRunner$Unstable" />
-    </org.jenkinsci.plugins.conditionalbuildstep.singlestep.SingleConditionalBuilder>
-  </builders>
-  <publishers>
-    <hudson.tasks.junit.JUnitResultArchiver >
-      <testResults>bazel-testlogs/**/test.xml, bazel-testlogs/**/dummy.xml</testResults>
-      <keepLongStdio>false</keepLongStdio>
-      <healthScaleFactor>1.0</healthScaleFactor>
-      <allowEmptyResults>true</allowEmptyResults>
-    </hudson.tasks.junit.JUnitResultArchiver>
-    {% if variables.SEND_EMAIL == "1" %}
-    <hudson.tasks.Mailer >
-      <recipients>{{ variables.BAZEL_BUILD_RECIPIENT }}</recipients>
-      <dontNotifyEveryUnstableBuild>false</dontNotifyEveryUnstableBuild>
-      <sendToIndividuals>false</sendToIndividuals>
-    </hudson.tasks.Mailer>
-    {% endif %}
-  </publishers>
-  <buildWrappers>
-    <hudson.plugins.build__timeout.BuildTimeoutWrapper>
-      <strategy class="hudson.plugins.build_timeout.impl.AbsoluteTimeOutStrategy">
-        <timeoutMinutes>240</timeoutMinutes>
-      </strategy>
-      <operationList>
-        <hudson.plugins.build__timeout.operations.FailOperation/>
-        <hudson.plugins.build__timeout.operations.WriteDescriptionOperation>
-          <description>Timed out</description>
-        </hudson.plugins.build__timeout.operations.WriteDescriptionOperation>
-      </operationList>
-    </hudson.plugins.build__timeout.BuildTimeoutWrapper>
-    {% if variables.SAUCE_ENABLED == "true" %}
-    <hudson.plugins.sauce_ondemand.SauceOnDemandBuildWrapper>
-      <enableSauceConnect>true</enableSauceConnect>
-      <credentialId>61b4846b-279d-4369-ae20-31e9d8b9bc66</credentialId>
-      <useGeneratedTunnelIdentifier>true</useGeneratedTunnelIdentifier>
-      <launchSauceConnectOnSlave>true</launchSauceConnectOnSlave>
-    </hudson.plugins.sauce_ondemand.SauceOnDemandBuildWrapper>
-    {% endif %}
-  </buildWrappers>
-  <executionStrategy class="hudson.matrix.DefaultMatrixExecutionStrategyImpl">
-    <runSequentially>{{ variables.RUN_SEQUENTIAL }}</runSequentially>
-  </executionStrategy>
-</matrix-project>
-
diff --git a/jenkins/build_defs/jenkins_job.bzl b/jenkins/build_defs/jenkins_job.bzl
index 7ac7f4c..0d23b90 100644
--- a/jenkins/build_defs/jenkins_job.bzl
+++ b/jenkins/build_defs/jenkins_job.bzl
@@ -22,7 +22,7 @@
 
 def jenkins_job(name, config, substitutions = {}, deps = [], deps_aliases = {},
                 project='bazel', org='bazelbuild', git_url=None, project_url=None,
-                folder=None, platforms=[], test_platforms=["linux-x86_64"],
+                folder=None, test_platforms=["linux-x86_64"],
                 create_filegroups=True):
   """Create a job configuration on Jenkins.
 
@@ -35,7 +35,6 @@
      org: the project organization on github, default 'bazelbuild'
      git_url: the URL to the git project, defaulted to the Github URL
      project_url: the project url, defaulted to the Git URL
-     platforms: platforms on which to run that job, default None,
      test_platforms: platforms on which to run that job when inside of a
        dockerized test, by default only 'linux-x86_64'
      create_filegroups: create filegroups named <name>/all, <name>/staging
@@ -56,7 +55,6 @@
       "GIT_URL": git_url,
       "GITHUB_PROJECT": github_project,
       "PROJECT_URL": project_url,
-      "PLATFORMS": "\n".join(platforms),
       "production": "true",
       } + MAIL_SUBSTITUTIONS
   substitutions["SEND_EMAIL"] = "1"
@@ -89,7 +87,6 @@
     native.filegroup(name = name + "/staging", srcs = [name + "-staging"])
 
   if test_platforms:
-    substitutions["PLATFORMS"] = "\n".join(test_platforms)
     substitutions["RESTRICT_CONFIGURATION"] += " + [node:%s]" % _to_groovy_list(test_platforms)
     expand_template(
       name = name + "-test",
@@ -111,16 +108,8 @@
     kwargs["git_url"] = kwargs
   bazel_github_job(**kwargs)
 
-def bazel_github_job(name, platforms=[], branch="master", project=None, org="google",
-                     project_url=None, workspace=".", configure=[], git_url=None,
-                     bazel_versions=["HEAD", "latest"],
-                     tests=["//..."], targets=["//..."], substitutions={},
-                     windows_configure=[],
-                     windows_tests=["//..."], windows_targets=["//..."],
-                     windows_tests_msys=["//..."], windows_targets_msys=["//..."],
-                     test_opts=["--test_output=errors", "--build_tests_only"],
-                     test_tag_filters=["-noci", "-manual"],
-                     build_opts=["--verbose_failures"],
+def bazel_github_job(name, branch="master", project=None, org="bazelbuild",
+                     project_url=None, workspace=".", git_url=None,
                      config="//jenkins/build_defs:default.json",
                      test_platforms=["linux-x86_64"],
                      enable_trigger=True,
@@ -129,35 +118,24 @@
                      pr_enabled=True,
                      github_enabled=True,
                      run_sequential=False,
-                     sauce_enabled=False):
+                     sauce_enabled=False,
+                     use_upstream_branch=False):
   """Create a generic github job configuration to build against Bazel head."""
   if not project:
     project = name
 
-  substitutions = substitutions + {
+  substitutions = {
     "WORKSPACE": workspace,
     "PROJECT_NAME": project,
     "BRANCH": branch,
     "NAME": name,
-    "CONFIGURE": "\n".join(configure),
-    "WINDOWS_CONFIGURE": "\n".join(windows_configure),
-    "TEST_OPTS": " ".join(test_opts),
-    "TEST_TAG_FILTERS": ",".join(test_tag_filters),
-    "BUILD_OPTS": " ".join(build_opts),
-    "TESTS": " + ".join(tests),
-    "WINDOWS_TESTS": " ".join(windows_tests),
-    # TODO(pcloudy): remove *_MSYS attributes when we don't need MSYS anymore
-    "WINDOWS_TESTS_MSYS": " ".join(windows_tests_msys),
-    "BUILDS": " ".join(targets),
-    "WINDOWS_BUILDS": " ".join(windows_targets),
-    "WINDOWS_BUILDS_MSYS": " ".join(windows_targets_msys),
-    "BAZEL_VERSIONS": "\n".join(bazel_versions),
     "disabled": str(not enabled).lower(),
     "enable_trigger": str(enable_trigger and github_enabled).lower(),
     "github": str(github_enabled),
-    "GERRIT_PROJECT": str(gerrit_project),
+    "GERRIT_PROJECT": str(gerrit_project) if gerrit_project else "",
     "RUN_SEQUENTIAL": str(run_sequential).lower(),
     "SAUCE_ENABLED": str(sauce_enabled).lower(),
+    "GLOBAL_USE_UPSTREAM_BRANCH": str(use_upstream_branch)
   }
 
   all_files = [name + ".xml"]
@@ -175,13 +153,9 @@
       project=project,
       org=org,
       project_url=project_url,
-      platforms=platforms,
       test_platforms = test_platforms,
       create_filegroups=False)
 
-  substitutions["BAZEL_VERSIONS"] = "\n".join([
-      v for v in bazel_versions if not v.startswith("HEAD")])
-
   if enabled and config:
     jenkins_job(
         name = "Global/" + name,
@@ -194,7 +168,6 @@
         project=project,
         org=org,
         project_url=project_url,
-        platforms=platforms,
         test_platforms=test_platforms,
         create_filegroups=False)
     all_files.append("Global/%s.xml" % name)
@@ -212,7 +185,6 @@
         project=project,
         org=org,
         project_url=project_url,
-        platforms=platforms,
         test_platforms=test_platforms,
         create_filegroups=False)
     all_files.append("PR/%s.xml" % name)
@@ -230,7 +202,6 @@
         project=project,
         org=org,
         project_url=project_url,
-        platforms=platforms,
         test_platforms=test_platforms)
     all_files.append("CR/%s.xml" % name)
     test_files.append("CR/%s-test.xml" % name)
diff --git a/jenkins/config/config.xml.tpl b/jenkins/config/config.xml.tpl
index 8bf32d5..6ae1215 100644
--- a/jenkins/config/config.xml.tpl
+++ b/jenkins/config/config.xml.tpl
@@ -26,9 +26,7 @@
       <filterExecutors>false</filterExecutors>
       <filterQueue>false</filterQueue>
       <properties class="hudson.model.View$PropertyList"/>
-      <jobNames>
-        {% for v in variables.GITHUB_JOBS.split(", ") %}<string>{{ v }}</string>{% endfor %}
-      </jobNames>
+      <jobNames/>
       <jobFilters/>
       <columns>
         <hudson.views.StatusColumn/>
@@ -40,6 +38,8 @@
         <hudson.views.BuildButtonColumn/>
       </columns>
       <recurse>false</recurse>
+      <includeRegex>(?!(install-bazel|Github-Trigger|PR|CR|Global|.*-Benchmark).*).*</includeRegex>
+      <statusFilter>true</statusFilter>
     </listView>
     <listView>
       <owner class="hudson" reference="../../.."/>
@@ -47,9 +47,7 @@
       <filterExecutors>false</filterExecutors>
       <filterQueue>false</filterQueue>
       <properties class="hudson.model.View$PropertyList"/>
-      <jobNames>
-        {% for v in variables.BAZEL_JOBS.split(", ") %}<string>{{ v }}</string>{% endfor %}
-      </jobNames>
+      <jobNames/>
       <jobFilters/>
       <columns>
         <hudson.views.StatusColumn/>
@@ -60,7 +58,9 @@
         <hudson.views.LastDurationColumn/>
         <hudson.views.BuildButtonColumn/>
       </columns>
+      <includeRegex>(install-bazel|Github-Trigger|PR|CR|Global|.*-Benchmark.*)</includeRegex>
       <recurse>false</recurse>
+      <statusFilter>true</statusFilter>
     </listView>
     <com.smartcodeltd.jenkinsci.plugins.buildmonitor.BuildMonitorView>
       <owner class="hudson" reference="../../.."/>
@@ -68,18 +68,17 @@
       <filterExecutors>false</filterExecutors>
       <filterQueue>false</filterQueue>
       <properties class="hudson.model.View$PropertyList"/>
-      <jobNames>
-        <comparator class="hudson.util.CaseInsensitiveComparator"/>{% for v in variables.IMPORTANT_JOBS.split(", ")|sort %}
-        <string>{{ v }}</string>{% endfor %}
-      </jobNames>
+      <jobNames/>
       <jobFilters/>
       <columns/>
-      <recurse>true</recurse>
       <title>Bazel Tests</title>
       <config>
         <displayCommitters>false</displayCommitters>
         <order class="com.smartcodeltd.jenkinsci.plugins.buildmonitor.order.ByName"/>
       </config>
+      <includeRegex>Global.*</includeRegex>
+      <recurse>true</recurse>
+      <statusFilter>true</statusFilter>
     </com.smartcodeltd.jenkinsci.plugins.buildmonitor.BuildMonitorView>
   </views>
   <primaryView>Projects</primaryView>
diff --git a/jenkins/jobs/BUILD b/jenkins/jobs/BUILD
index b0fe279..8abfaa1 100644
--- a/jenkins/jobs/BUILD
+++ b/jenkins/jobs/BUILD
@@ -1,25 +1,14 @@
 load("//jenkins/build_defs:jenkins.bzl", "jenkins_job", "bazel_github_job", "bazel_git_job")
-load(
-    ":jobs.bzl",
-    "LINUX_PLATFORMS",
-    "UNIX_PLATFORMS",
-    "DARWIN_PLATFORMS",
-    "WINDOWS_PLATFORMS",
-    "ALL_PLATFORMS",
-    "RULES",
-    "DISABLED_RULES",
-    "BAZEL_JOBS",
-    "JOBS",
-    "JOBS_SUBSTITUTIONS",
-    "STAGING_JOBS",
-)
+load(":jobs.bzl", "job_lists")
 load("//jenkins/lib:def.bzl", "bazel_job_configuration_test")
 
+# Tests
 [bazel_job_configuration_test(
     name = s + "-test",
     configs = [s],
 ) for s in glob(["configs/*.json"])]
 
+# Some common jobs
 jenkins_job(
     name = "Github-Trigger",
     config = "jobs-Github-Trigger.xml.tpl",
@@ -30,7 +19,10 @@
     name = job,
     config = "jobs-%s.xml.tpl" % job,
     project_url = "http://bazel.io",
-) for job in ["Bazel-Benchmark", "Bazel-Push-Benchmark-Output"]]
+) for job in [
+    "Bazel-Benchmark",
+    "Bazel-Push-Benchmark-Output",
+]]
 
 jenkins_job(
     name = "Global/pipeline",
@@ -56,316 +48,144 @@
     deps = [":install-bazel.groovy"],
 )
 
-# TODO(dmarting): activate Tensorflow on mac (missing dependencies)
+##
+## list of projects
+##
+
+# Jobs from the tensorflow org
 bazel_github_job(
     name = "TensorFlow",
-    build_opts = ["-c opt"],
     config = ":configs/tensorflow.json",
-    configure = ["./tensorflow/tools/ci_build/builds/configured CPU"],
     org = "tensorflow",
-    platforms = LINUX_PLATFORMS + WINDOWS_PLATFORMS,
     project_url = "https://tensorflow.org",
-    targets = ["//tensorflow/tools/pip_package:build_pip_package"],
-    test_opts = [
-        "--test_timeout=1800",
-        "--test_output=errors",
-    ],
-    tests = ["filter(\":(lib|platform)_.*\", kind(test, //tensorflow/core:all))"],
-    windows_configure = [
-        # run.bat invokes msys bash to run the shell script for building TF,
-        # But msys bash doesn't inherit PATH from cmd.exe, so we make bazel avaiable by
-        # copying it to c:\\tools\\msys64\\usr\\bin\\bazel.exe
-        "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",
-    ],
-    windows_targets = [],
-    windows_tests = [],
 )
 
 bazel_github_job(
     name = "TensorFlow_Serving",
     config = ":configs/tensorflow_serving.json",
-    configure = ["(cd tensorflow && ln -s ../.bazelrc && ./tensorflow/tools/ci_build/builds/configured CPU)"],
     org = "tensorflow",
-    platforms = LINUX_PLATFORMS,
     project = "serving",
-    targets = [],
-    tests = ["tensorflow_serving/..."],
 )
 
 bazel_github_job(
     name = "tf_models_syntaxnet",
     config = ":configs/tf_models_syntaxnet.json",
-    configure = ["(cd tensorflow && ln -s ../.bazelrc && ./tensorflow/tools/ci_build/builds/configured CPU)"],
     org = "tensorflow",
-    platforms = LINUX_PLATFORMS,
     project = "models",
-    targets = [],
-    tests = [
-        "syntaxnet/...",
-        "util/utf8/...",
-    ],
     workspace = "syntaxnet",
 )
 
-bazel_github_job(
-    name = "Tutorial",
-    config = ":configs/tutorial.json",
-    configure = ["source ./ci/setup_android_repositories.sh"],
-    org = "bazelbuild",
-    platforms = UNIX_PLATFORMS,
-    project = "examples",
-    targets = ["//:all"],
-    tests = [],
-    workspace = "tutorial",
-)
-
+# Job for testing Gerrit
 bazel_git_job(
     name = "gerrit",
     config = ":configs/gerrit.json",
     git_url = "https://gerrit.googlesource.com/gerrit",
     org = "GerritCodeReview",
-    platforms = UNIX_PLATFORMS,
     project = "gerrit",
     project_url = "https://www.gerritcodereview.com",
-    targets = ["//:release"],
-    tests = ["//..."],
+)
+
+# Jobs from the bazelbuild org with customization
+bazel_github_job(
+    name = "Tutorial",
+    config = ":configs/tutorial.json",
+    project = "examples",
+    workspace = "tutorial",
 )
 
 bazel_github_job(
     name = "bazel-docker-tests",
-    bazel_versions = [
-        "HEAD",
-        "latest",
-    ],
     config = ":configs/bazel-docker-tests.json",
     enable_trigger = False,
     git_url = "https://bazel.googlesource.com/bazel",
-    org = "bazelbuild",
-    platforms = ["docker"],
     pr_enabled = False,  # Do not vet PR because those tests are slow.
     project = "bazel",
-    substitutions = {"GLOBAL_USE_UPSTREAM_BRANCH": "True"},
-    targets = [],
-    tests = [
-        "filter(\"^//src/test/docker\", //src/test/...)",
-        "//tools/cpp/...",
-    ],
+    use_upstream_branch = True,
 )
 
 bazel_github_job(
     name = "eclipse",
-    bazel_versions = [
-        "HEAD",
-        "latest",
-    ],
     gerrit_project = "eclipse",
-    org = "bazelbuild",
-    platforms = UNIX_PLATFORMS,
 )
 
 bazel_github_job(
     name = "continuous-integration",
-    bazel_versions = [
-        "HEAD",
-        "latest",
-    ],
     config = ":configs/continuous-integration.json",
     gerrit_project = "continuous-integration",
-    org = "bazelbuild",
-    platforms = ["docker"],
 )
 
 bazel_github_job(
     name = "bazel-tests",
-    bazel_versions = [
-        "HEAD",
-        "latest",
-    ],
-    build_opts = [
-        "--verbose_failures",
-        # TODO(pcloudy): This is only for Windows.
-        # Remove it after wrapper-less CROSSTOOL becomes default
-        "--action_env=NO_MSVC_WRAPPER=1",
-        # TODO(pcloudy): Remove this after TEMP is properly set.
-        # A workaround for ASSERT_DEATH in gtest on Windows.
-        # When running tests, Bazel doesn't set TEMP,
-        # ASSERT_DEATH will try to write to C:/Windows, then fails.
-        "--test_env=TEMP",
-    ],
     config = ":configs/bazel-tests.json",
-    configure = [
-        "source scripts/ci/build.sh",
-        "setup_android_repositories",
-    ],
     enable_trigger = False,
     gerrit_project = "bazel",
     git_url = "https://bazel.googlesource.com/bazel",
-    org = "bazelbuild",
-    platforms = ALL_PLATFORMS,
     project = "bazel",
-    substitutions = {"GLOBAL_USE_UPSTREAM_BRANCH": "True"},
-    targets = [],
-    test_opts = [
-        "-k",
-        "--test_output=errors",
-        "--build_tests_only",
-    ],
-    tests = [
-        "filter(\"^(?!//src/test/docker).*$\", //src/test/...)",
-        "//scripts/...",
-        "//third_party/ijar/...",
-        "//tools/android/...",
-    ],
-    windows_targets = [
-        "//src:bazel",
-    ],
-    windows_targets_msys = [
-    ],
-    windows_tests = [
-        "//src/test/py/...",
-        "//src/test/java/...",
-        "//src/test/cpp/...",
-        "//src/test/native:all_tests",
-        "//src/tools/launcher/util/...",
-        "//src/test/shell/bazel:bazel_bootstrap_distfile_test",
-        "//src/test/shell/bazel:bazel_windows_example_test",
-    ],
-    windows_tests_msys = [
-        "//src/test/shell/bazel:bazel_windows_example_test",
-    ],
+    use_upstream_branch = True,
 )
 
 bazel_github_job(
     name = "buildifier",
     config = ":configs/buildifier.json",
-    org = "bazelbuild",
-    platforms = UNIX_PLATFORMS,
     # Repository was renamed
     project = "buildtools",
-    targets = [],
-    tests = [":tests"],
 )
 
-bazel_github_job(
-    name = "rules_scala",
-    config = ":configs/rules_scala.json",
-    org = "bazelbuild",
-    platforms = UNIX_PLATFORMS,
-    targets = ["//test/..."],
-    tests = ["//test/..."],
-)
-
-bazel_github_job(
-    name = "rules_rust",
-    config = ":configs/rules_rust.json",
-    org = "bazelbuild",
-    platforms = UNIX_PLATFORMS,
-    targets = [
-        "//...",
-        "@examples//...",
-    ],
-    tests = [
-        "//...",
-        "@examples//...",
-    ],
-)
-
-# Special case rules_dotnet that runs only on darwin platforms
-bazel_github_job(
-    name = "rules_dotnet",
-    config = ":configs/rules_dotnet.json",
-    org = "bazelbuild",
-    platforms = DARWIN_PLATFORMS,
-)
-
-bazel_github_job(
-    name = "rules_jsonnet",
-    config = ":configs/rules_jsonnet.json",
-    org = "bazelbuild",
-    platforms = UNIX_PLATFORMS,
-    targets = [
-        "//...",
-        "@examples//...",
-    ],
-    tests = [
-        "//...",
-        "@examples//...",
-    ],
-)
-
-[bazel_github_job(
-    name = job,
-    org = "bazelbuild",
-    platforms = UNIX_PLATFORMS,
-) for job in RULES]
-
 # rules_web was renamed to rules_webtesting, keep the legacy name
 # for the job to keep history but use the new project name.
 bazel_github_job(
     name = "rules_web",
-    org = "bazelbuild",
-    platforms = UNIX_PLATFORMS,
     project = "rules_webtesting",
     run_sequential = True,
     sauce_enabled = True,
 )
 
-[bazel_github_job(
-    name = job,
-    enabled = False,
-    org = "bazelbuild",
-    platforms = UNIX_PLATFORMS,
-) for job in DISABLED_RULES]
-
 bazel_github_job(
     name = "intellij",
-    build_opts = ["--define=ij_product=intellij-latest"],
     config = ":configs/intellij.json",
-    org = "bazelbuild",
-    platforms = UNIX_PLATFORMS,
     project = "intellij",
     project_url = "https://ij.bazel.io",
-    targets = ["ijwb:ijwb_bazel"],
-    test_opts = ["--define=ij_product=intellij-latest"],
-    tests = [":ijwb_tests"],
 )
 
-bazel_github_job(
-    name = "migration-tooling",
-    org = "bazelbuild",
-    platforms = UNIX_PLATFORMS,
-)
+# Jobs from the bazelbuild org that have a specific config on continuous-integration
+# side.
+# TODO(dmarting): merge with the next list once we move those configuration file
+# on the repository side.
+[bazel_github_job(
+    name = n,
+    config = ":configs/%s.json" % n,
+) for n in [
+    "rules_scala",
+    "rules_rust",
+    "rules_dotnet",
+    "rules_jsonnet",
+]]
 
+# Jobs from the bazelbuild org using the default configuration
+[bazel_github_job(name = n) for n in [
+    "rules_appengine",
+    "rules_closure",
+    "rules_d",
+    "rules_go",
+    "rules_sass",
+    "rules_gwt",
+    "rules_groovy",
+    "rules_perl",
+    "rules_docker",
+    "skydoc",
+    "bazel-watcher",
+    "migration-tooling",
+]]
+
+# Jobs from the google org
 [bazel_github_job(
     name = n,
     config = ":configs/%s.json" % n,
     org = "google",
-    platforms = UNIX_PLATFORMS,
-    # on Linux protobuf tries to build objc target so filter by test only
-    targets = [],
-    tests = [":all"],
 ) for n in [
     "re2",
     "protobuf",
 ]]
 
-filegroup(
-    name = "jobs",
-    srcs = ["%s/all" % j for j in JOBS],
-    visibility = ["//jenkins:__pkg__"],
-)
-
-filegroup(
-    name = "staging-jobs",
-    srcs = ["%s/staging" % j for j in STAGING_JOBS],
-    visibility = ["//jenkins:__pkg__"],
-)
-
-filegroup(
-    name = "test-jobs",
-    # We include all test but the docker ones (they needs access to the docker server).
-    srcs = ["%s/test" % j for j in JOBS if not "docker" in j],
-    visibility = ["//jenkins:__pkg__"],
-)
+# End of project list
+job_lists(visibility = ["//jenkins:__pkg__"])
diff --git a/jenkins/jobs/Bazel.unix.sh.tpl b/jenkins/jobs/Bazel.unix.sh.tpl
deleted file mode 100644
index 1d7ebb3..0000000
--- a/jenkins/jobs/Bazel.unix.sh.tpl
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/usr/bin/env bash
-# Copyright 2016 The Bazel Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Shell script to set-up the environment on Linux and Darwin to bootstrap
-# bazel.
-
-source scripts/ci/build.sh
-
-export BUILD_BY="Jenkins"
-export BUILD_LOG="${BUILD_URL}"
-export GIT_REPOSITORY_URL="${GIT_URL}"
-export BAZEL_COMPILE_TARGET="compile,srcs,determinism"
-export BOOTSTRAP_BAZEL="${HOME}/.bazel/latest/binary/bazel"
-
-if [[ "${NODE_LABELS}" =~ "no-release" ]]; then
-  bazel_build
-else
-  bazel_build output/ci
-fi
-
diff --git a/jenkins/jobs/Bazel.win.sh.tpl b/jenkins/jobs/Bazel.win.sh.tpl
deleted file mode 100644
index 26dba4d..0000000
--- a/jenkins/jobs/Bazel.win.sh.tpl
+++ /dev/null
@@ -1,39 +0,0 @@
-# Copyright 2016 The Bazel Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Shell script to set-up the environment on Windows to call the bootstrap
-# inside MSYS.
-
-set -eux
-
-# We have to strip the environment or the windows env will override the 
-# Bazel latest to bootstrap bazel
-echo 'export BOOTSTRAP_BAZEL="/c/bazel_ci/installs/bootstrap/bazel.exe"' >env.sh
-
-# Pass PLATFORM_NAME to Windows bootstrap script for building a MSVC Bazel
-echo "export PLATFORM_NAME=\"${PLATFORM_NAME}\"" >>env.sh
-
-# Various set-up for the slave
-echo 'export TMPDIR="${TMPDIR:-/c/bazel_ci/temp}"' >>env.sh
-echo 'mkdir -p "${TMPDIR}"' >>env.sh
-echo 'export PATH="$PATH:/c/python_27_amd64/files"' >>env.sh
-
-# Get java home
-echo "export JAVA_HOME='$(dirname "$(dirname "$(which java)")")'" >>env.sh
-
-# Jenkins is capable of executing shell scripts directly, even on Windows,
-# but it uses a shell binary bundled with it and not the msys one. We don't
-# want to use two different shells, so a batch file is used instead to call
-# the msys shell.
-/c/tools/msys64/usr/bin/bash -l -c "cd $PWD; source env.sh; exec ./scripts/ci/windows/compile_windows.sh"
diff --git a/jenkins/jobs/jobs.bzl b/jenkins/jobs/jobs.bzl
index 7d89f0e..d876ae1 100644
--- a/jenkins/jobs/jobs.bzl
+++ b/jenkins/jobs/jobs.bzl
@@ -1,88 +1,39 @@
-LINUX_PLATFORMS = [
-    "linux-x86_64",
-    "ubuntu_16.04-x86_64",
-]
+def _is_staging(job):
+  job_desc = native.existing_rule(job + "-staging")
+  job_subs = job_desc["substitutions"]
+  is_bazel = "PROJECT_NAME" in job_subs
+  is_gerrit = "GERRIT_PROJECT" in job_subs and job_subs["GERRIT_PROJECT"] != ""
+  # Take job with Gerrit review, or jobs that are not bazel jovbs
+  is_gerrit_or_not_bazel = is_gerrit or not is_bazel
+  # Exclude Benchmark jobs
+  is_not_benchmark = "-Benchmark" not in job
+  # Gold jobs are some bazel job that we include for testing
+  is_gold = job in ["TensorFlow", "Tutorial"]
+  return (is_gold or is_gerrit_or_not_bazel) and is_not_benchmark
 
-BSD_PLATFORMS = ["freebsd-11", "freebsd-12"]
 
-DARWIN_PLATFORMS = ["darwin-x86_64"]
+def _is_testing(job):
+  # We include all test but the docker ones (they needs access to the docker server).
+  return not "docker" in job and job != "continuous-integration"
 
-WINDOWS_PLATFORMS = ["windows-x86_64"]
 
-UNIX_PLATFORMS = LINUX_PLATFORMS + DARWIN_PLATFORMS
+def job_lists(name = "jobs", visibility = None):
+  jobs = native.existing_rules()
 
-ALL_PLATFORMS = UNIX_PLATFORMS + WINDOWS_PLATFORMS
+  native.filegroup(
+    name = name,
+    srcs = [j for j in jobs if j.endswith("/all")],
+    visibility = visibility,
+  )
 
-RULES = [
-    "rules_appengine",
-    "rules_closure",
-    "rules_d",
-    "rules_go",
-    "rules_sass",
-    "rules_gwt",
-    "rules_groovy",
-    "rules_perl",
-    "rules_docker",
-    # These are not really rules, but it is simpler to put here.
-    "skydoc",
-    "bazel-watcher",
-]
+  native.filegroup(
+    name = "staging-" + name,
+    srcs = [j for j in jobs if j.endswith("/staging") and _is_staging(j[:-8])],
+    visibility = visibility,
+  )
 
-DISABLED_RULES = []
-
-GERRIT_JOBS = [
-    "bazel-tests",
-    "continuous-integration",
-    "eclipse",
-]
-
-GITHUB_JOBS = [
-    "TensorFlow",
-    "TensorFlow_Serving",
-    "tf_models_syntaxnet",
-    "Tutorial",
-    "re2",
-    "protobuf",
-    "gerrit",
-    # rules_dotnet is disabled on Linux until bazelbuild/rules_dotnet#13 is fixed.
-    "rules_dotnet",
-    # rules_web was renamed to rules_webtesting, keep the legacy name
-    # for the job to keep history but use the new project name.
-    "rules_web",
-    "intellij",
-    "buildifier",
-    "rules_jsonnet",
-    "rules_rust",
-    "rules_scala",
-    "migration-tooling",
-] + GERRIT_JOBS + RULES + DISABLED_RULES
-
-NO_PR_JOBS = ["bazel-docker-tests"]
-
-BAZEL_STAGING_JOBS = [
-    "Github-Trigger",
-    "Global/pipeline",
-    "CR/global-verifier",
-    "install-bazel",
-]
-
-BAZEL_JOBS = BAZEL_STAGING_JOBS + [
-    "Bazel-Benchmark",
-    "Bazel-Push-Benchmark-Output",
-]
-
-JOBS = BAZEL_JOBS + GITHUB_JOBS + NO_PR_JOBS
-
-JOBS_SUBSTITUTIONS = {
-    "GITHUB_JOBS": ", ".join(GITHUB_JOBS + NO_PR_JOBS),
-    "BAZEL_JOBS": ", ".join(BAZEL_JOBS),
-    "IMPORTANT_JOBS": ", ".join(GITHUB_JOBS + NO_PR_JOBS + ["Bazel", "Bazel-Publish-Site", "Bazel-Install-Trigger"])
-}
-
-STAGING_GITHUB_JOBS = GERRIT_JOBS + ["TensorFlow", "Tutorial"]
-STAGING_JOBS = BAZEL_STAGING_JOBS + STAGING_GITHUB_JOBS
-STAGING_JOBS_SUBSTITUTIONS = {
-    "GITHUB_JOBS": ", ".join(STAGING_GITHUB_JOBS),
-    "BAZEL_JOBS": ", ".join(BAZEL_STAGING_JOBS),
-    "IMPORTANT_JOBS": ", ".join(STAGING_GITHUB_JOBS + ["Bazel", "Bazel-Publish-Site", "Bazel-Install-Trigger"])
-}
+  native.filegroup(
+    name = "test-" + name,
+    srcs = [j for j in jobs if j.endswith("/test") and _is_testing(j[:-5])],
+    visibility = visibility,
+  )