Reorganize jobs

Jobs are now grouped in folder by topic:

  - bazel contains the presubmit, and post-submit (splitted into nightly
  and release, reverting a86356a in the process). Fixes #94. The nightly
  build can be re-run on demand by the sheriff so no need to run it on
  every push.
  - maintenance contains pure maintenance jobs

Fixes #120.

Change-Id: I6ff44b6aa7003eedf5e50de7c5f5d090a2598a4d
diff --git a/docs/jobs.md b/docs/jobs.md
index c3051e1..9a1fa91 100644
--- a/docs/jobs.md
+++ b/docs/jobs.md
@@ -5,13 +5,21 @@
 
 ## Bootstrap and maintenance
 
-Four jobs control the bootstrap and maintenance of Bazel:
+Several jobs control the bootstrap and maintenance of Bazel, they
+are mostly under the `maintenance` and `bazel` folders:
 
-* `Bazel-Benchmark` and `Bazel-Push-Benchmark-Output`: jobs running
-  continously to produce benchmarks of Bazel published at [perf.bazel.build](https://perf.bazel.build).
-* `Global/pipeline`: a job that handles the global tests as well as the release process, it is run
-   every night and on release.
-* `install-bazel`: a job that install Bazel release on all the slaves.
+* `benchmark`: job running continously to produce benchmarks of
+   Bazel published at [perf.bazel.build](https://perf.bazel.build).
+* `maintenance/push-benchmark`: job running after `benchmark` to publish
+   the performance test to the website.
+* `maintenance/install-bazel`: job that install Bazel release on all the slaves.
+* `maintenance/gerrit-verifier`: job to detect pending reviews on Gerrit that
+   need validation (that have been marked as `Presubmit-Ready`).
+* `bazel/nightly`: job that handles the global tests, it runs every night.
+* `bazel/release`: copy of `bazel/nightly` that runs for the release, it also
+   handle publishing the release artifacts.
+* `bazel/presubmit`: copy of `bazel/nightly` that is triggered
+  when someone set `Presubmit-Ready+2` on Gerrit.
 
 ## Projects
 
@@ -25,10 +33,6 @@
 
 ## Hidden jobs
 
-* `CR/gerrit-verifier` is a job to detect pending reviews on Gerrit that
-  need validation (that have been marked as `Presubmit-Ready`).
-* `CR/global-verifier` is a clone of `Global/pipeline` that is triggered
-  when someone set `Presubmit-Ready+2` on Gerrit.
 * `PR/_project_` is a copy of the job for _project_ that validates a GitHub pull
   request on _project_ with the latest release of Bazel.
 * `CR/_project_` is the same as `PR-_project_` but for validating Gerrit
diff --git a/jenkins/BUILD b/jenkins/BUILD
index 7466330..d032f6f 100644
--- a/jenkins/BUILD
+++ b/jenkins/BUILD
@@ -190,7 +190,7 @@
 
 # Jenkins job for Gerrit vetting
 jenkins_job(
-    name = "CR/gerrit-verifier",
+    name = "maintenance/gerrit-verifier",
     config = "gerrit-verifier.xml.tpl",
     project_url = "https://bazel-review.googlesource.com",
     deps = ["gerrit-verifier.groovy"],
@@ -279,7 +279,7 @@
               jenkins_node_names(FREEBSD_12_PREFIX, FREEBSD_12_COUNT),
     jobs = [
         "//jenkins/jobs",
-        ":CR/gerrit-verifier",
+        ":maintenance/gerrit-verifier",
     ],
     substitutions = {
         "SECURITY_CONFIG": SECURITY_CONFIG,
@@ -304,7 +304,7 @@
     ],
     jobs = [
         "//jenkins/jobs:staging-jobs",
-        ":CR/gerrit-verifier/staging",
+        ":maintenance/gerrit-verifier/staging",
     ],
     substitutions = {
         "SECURITY_CONFIG": SECURITY_CONFIG,
@@ -325,7 +325,7 @@
     ],
     jobs = [
         "//jenkins/jobs:test-jobs",
-        ":CR/gerrit-verifier/test",
+        ":maintenance/gerrit-verifier/test",
     ],
     substitutions = {
         "SECURITY_CONFIG": "<useSecurity>false</useSecurity>",
diff --git a/jenkins/config/config.xml.tpl b/jenkins/config/config.xml.tpl
index 7c508dd..7f21e8e 100644
--- a/jenkins/config/config.xml.tpl
+++ b/jenkins/config/config.xml.tpl
@@ -38,7 +38,7 @@
         <hudson.views.BuildButtonColumn/>
       </columns>
       <recurse>false</recurse>
-      <includeRegex>(?!(install-bazel|Github-Trigger|PR|CR|Global|.*-Benchmark).*).*</includeRegex>
+      <includeRegex>(?!(bazel|PR|CR|maintenance|Global|benchmark)).*</includeRegex>
       <statusFilter>true</statusFilter>
     </listView>
     <listView>
@@ -58,7 +58,7 @@
         <hudson.views.LastDurationColumn/>
         <hudson.views.BuildButtonColumn/>
       </columns>
-      <includeRegex>(install-bazel|Github-Trigger|PR|CR|Global|.*-Benchmark.*)</includeRegex>
+      <includeRegex>(bazel|PR|CR|maintenance|Global|benchmark)</includeRegex>
       <recurse>false</recurse>
       <statusFilter>true</statusFilter>
     </listView>
@@ -76,7 +76,7 @@
         <displayCommitters>false</displayCommitters>
         <order class="com.smartcodeltd.jenkinsci.plugins.buildmonitor.order.ByName"/>
       </config>
-      <includeRegex>(Global/pipeline|(?!.*/).*)</includeRegex>
+      <includeRegex>(bazel/.*|(?!.*/).*)</includeRegex>
       <recurse>true</recurse>
       <statusFilter>true</statusFilter>
     </com.smartcodeltd.jenkinsci.plugins.buildmonitor.BuildMonitorView>
diff --git a/jenkins/gerrit-verifier.groovy b/jenkins/gerrit-verifier.groovy
index ff07586..87f1099 100644
--- a/jenkins/gerrit-verifier.groovy
+++ b/jenkins/gerrit-verifier.groovy
@@ -40,7 +40,7 @@
 def globalPresubmit(gerrit, change) {
   def refspec = "+" + change.ref + ":" + change.ref.replaceAll('ref/', 'ref/remotes/origin/')
   gerrit.startReview(change.number)
-  build job: "CR/global-verifier", propagate: false, wait: false, parameters: [
+  build job: "bazel/presubmit", propagate: false, wait: false, parameters: [
     [$class: 'StringParameterValue', name: 'REFSPEC', value: refspec],
     [$class: 'StringParameterValue', name: 'BRANCH', value: change.sha1],
     [$class: 'StringParameterValue', name: 'CHANGE_NUMBER', value: change.number.toString()]]
diff --git a/jenkins/jobs/BUILD b/jenkins/jobs/BUILD
index 9bc5353..8bc06fc 100644
--- a/jenkins/jobs/BUILD
+++ b/jenkins/jobs/BUILD
@@ -9,33 +9,28 @@
 ) for s in glob(["configs/*.json"])]
 
 # Some common jobs
-[jenkins_job(
-    name = job,
-    config = "jobs-%s.xml.tpl" % job,
+jenkins_job(
+    name = "benchmark",
+    config = "benchmark.xml.tpl",
     project_url = "http://bazel.io",
-) for job in [
-    "Bazel-Benchmark",
-    "Bazel-Push-Benchmark-Output",
-]]
+)
 
-jenkins_job(
-    name = "Global/pipeline",
-    config = "global.xml.tpl",
+[jenkins_job(
+    name = "bazel/" + job,
+    config = "global/%s.xml.tpl" % job,
     deps = [
         ":configs/bootstrap.json",
     ],
+) for job in ["nightly", "presubmit", "release"]]
+
+jenkins_job(
+    name = "maintenance/push-benchmark",
+    config = "push-benchmark.xml.tpl",
+    project_url = "http://bazel.io",
 )
 
 jenkins_job(
-    name = "CR/global-verifier",
-    config = "CR-global.xml.tpl",
-    deps = [
-        ":configs/bootstrap.json",
-    ],
-)
-
-jenkins_job(
-    name = "install-bazel",
+    name = "maintenance/install-bazel",
     config = "install-bazel.xml.tpl",
     deps = [":install-bazel.groovy"],
 )
diff --git a/jenkins/jobs/jobs-Bazel-Benchmark.xml.tpl b/jenkins/jobs/benchmark.xml.tpl
similarity index 98%
rename from jenkins/jobs/jobs-Bazel-Benchmark.xml.tpl
rename to jenkins/jobs/benchmark.xml.tpl
index bb3a6d2..4ab52e7 100644
--- a/jenkins/jobs/jobs-Bazel-Benchmark.xml.tpl
+++ b/jenkins/jobs/benchmark.xml.tpl
@@ -112,7 +112,7 @@
           <configs>
             <hudson.plugins.parameterizedtrigger.CurrentBuildParameters/>
           </configs>
-          <projects>Bazel-Push-Benchmark-Output</projects>
+          <projects>maintenance/push-benchmark</projects>
           <condition>UNSTABLE_OR_BETTER</condition>
           <triggerWithNoParameters>false</triggerWithNoParameters>
         </hudson.plugins.parameterizedtrigger.BuildTriggerConfig>
diff --git a/jenkins/jobs/global.xml.tpl b/jenkins/jobs/global/nightly.xml.tpl
similarity index 73%
rename from jenkins/jobs/global.xml.tpl
rename to jenkins/jobs/global/nightly.xml.tpl
index ce98f82..2b69a93 100644
--- a/jenkins/jobs/global.xml.tpl
+++ b/jenkins/jobs/global/nightly.xml.tpl
@@ -19,11 +19,6 @@
     </jenkins.model.BuildDiscarderProperty>
     <hudson.model.ParametersDefinitionProperty>
       <parameterDefinitions>
-        <hudson.model.StringParameterDefinition>
-          <name>payload</name>
-          <description>Payload sent by GitHub</description>
-          <defaultValue></defaultValue>
-        </hudson.model.StringParameterDefinition>
         <hudson.model.TextParameterDefinition>
           <name>EXTRA_BAZELRC</name>
           <description>To inject new option to the .bazelrc file in downstream projects.</description>
@@ -41,23 +36,16 @@
       </triggers>
     </org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
   </properties>
-  <authToken>##SECRET:github_trigger_auth_token##</authToken>
   <definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition">
     <script>
-githubHook(refs: '^refs/(heads/release-|tags/|heads/master).*$') {
-  def branch = delegate.branch ? delegate.branch :"master"
-  def refspec = branch.matches('^(refs/heads/)?master$') ?
-                        "+refs/heads/*:refs/remotes/origin/*" :
-                        "+refs/heads/*:refs/remotes/origin/* +refs/notes/*:refs/notes/*"
   globalBazelTest(
-      repository: delegate.url ? delegate.url : "https://bazel.googlesource.com/bazel",
-      branch: branch,
+      repository: "https://bazel.googlesource.com/bazel",
+      branch: "master",
       extra_bazelrc: params.EXTRA_BAZELRC,
-      refspec: refspec,
+      refspec: "+refs/heads/*:refs/remotes/origin/*",
       configuration: '''{{ raw_imports['//jenkins/jobs:configs/bootstrap.json'].replace('\\', '\\\\').replace("'", "\\'") }}''',
       restrict_configuration: {{ variables.RESTRICT_CONFIGURATION }},
       mail_recipient: "{{ variables.BAZEL_BUILD_RECIPIENT }}")
-}
   </script>
     <sandbox>true</sandbox>
   </definition>
diff --git a/jenkins/jobs/CR-global.xml.tpl b/jenkins/jobs/global/presubmit.xml.tpl
similarity index 100%
rename from jenkins/jobs/CR-global.xml.tpl
rename to jenkins/jobs/global/presubmit.xml.tpl
diff --git a/jenkins/jobs/global.xml.tpl b/jenkins/jobs/global/release.xml.tpl
similarity index 71%
copy from jenkins/jobs/global.xml.tpl
copy to jenkins/jobs/global/release.xml.tpl
index ce98f82..4c441c4 100644
--- a/jenkins/jobs/global.xml.tpl
+++ b/jenkins/jobs/global/release.xml.tpl
@@ -31,29 +31,16 @@
         </hudson.model.TextParameterDefinition>
       </parameterDefinitions>
     </hudson.model.ParametersDefinitionProperty>
-    <org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
-      <triggers>
-        {% if variables.production == "true" %}
-        <hudson.triggers.TimerTrigger>
-          <spec>@midnight</spec>
-        </hudson.triggers.TimerTrigger>
-        {% endif %}
-      </triggers>
-    </org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
   </properties>
   <authToken>##SECRET:github_trigger_auth_token##</authToken>
   <definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition">
     <script>
-githubHook(refs: '^refs/(heads/release-|tags/|heads/master).*$') {
-  def branch = delegate.branch ? delegate.branch :"master"
-  def refspec = branch.matches('^(refs/heads/)?master$') ?
-                        "+refs/heads/*:refs/remotes/origin/*" :
-                        "+refs/heads/*:refs/remotes/origin/* +refs/notes/*:refs/notes/*"
+githubHook(refs: '^refs/(heads/release-|tags/).*$') {
   globalBazelTest(
-      repository: delegate.url ? delegate.url : "https://bazel.googlesource.com/bazel",
-      branch: branch,
+      repository: delegate.url,
+      branch: delegate.branch,
       extra_bazelrc: params.EXTRA_BAZELRC,
-      refspec: refspec,
+      refspec: "+refs/heads/*:refs/remotes/origin/* +refs/notes/*:refs/notes/*",
       configuration: '''{{ raw_imports['//jenkins/jobs:configs/bootstrap.json'].replace('\\', '\\\\').replace("'", "\\'") }}''',
       restrict_configuration: {{ variables.RESTRICT_CONFIGURATION }},
       mail_recipient: "{{ variables.BAZEL_BUILD_RECIPIENT }}")
diff --git a/jenkins/jobs/jobs-Bazel-Push-Benchmark-Output.xml.tpl b/jenkins/jobs/push-benchmark.xml.tpl
similarity index 100%
rename from jenkins/jobs/jobs-Bazel-Push-Benchmark-Output.xml.tpl
rename to jenkins/jobs/push-benchmark.xml.tpl
diff --git a/jenkins/test/test_url_answer.sh b/jenkins/test/test_url_answer.sh
index 9cebdaa..e34e16e 100755
--- a/jenkins/test/test_url_answer.sh
+++ b/jenkins/test/test_url_answer.sh
@@ -24,10 +24,11 @@
 source "${PYTHON_RUNFILES}/io_bazel_ci/jenkins/test/test-support.sh"
 setup
 
-test_ok_status "/job/Global/job/pipeline/"
-test_ok_status "/job/install-bazel/"
-test_ok_status "/job/CR/job/gerrit-verifier"
-test_ok_status "/job/CR/job/global-verifier"
+test_ok_status "/job/bazel/job/presubmit/"
+test_ok_status "/job/bazel/job/nightly/"
+test_ok_status "/job/bazel/job/release/"
+test_ok_status "/job/maintenance/job/install-bazel/"
+test_ok_status "/job/maintenance/job/gerrit-verifier"
 
 test_ok_status "/job/rules_closure/"
 test_ok_status "/job/PR/job/rules_closure/"