Discard old builds for all jobs

Discard builds older than 90 days for regular jobs and older
than 25 builds for maintainance job. This should be accompanied
by an archiving of the build logs for release in case we need it.

Fixes #88.

Change-Id: I063f45dfead4f1861c3822978191c1d20816f5c2
diff --git a/jenkins/build_defs/bazel-job-Gerrit.xml.tpl b/jenkins/build_defs/bazel-job-Gerrit.xml.tpl
index 48a24be..7595285 100644
--- a/jenkins/build_defs/bazel-job-Gerrit.xml.tpl
+++ b/jenkins/build_defs/bazel-job-Gerrit.xml.tpl
@@ -1,7 +1,7 @@
 <?xml version='1.0' encoding='UTF-8'?>
 <flow-definition plugin="workflow-job">
   <actions/>
-  <description>Test Gerrit code review for {{ variables.PROJECT_NAME }}. 
+  <description>Test Gerrit code review for {{ variables.PROJECT_NAME }}.
 
 This job for testing changes submitted to the Gerrit project: {{ variables.GERRIT_PROJECT }}.
 </description>
@@ -10,6 +10,14 @@
     {% if variables.RUN_SEQUENTIAL == "true" %}
     <org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/>
     {% endif %}
+    <jenkins.model.BuildDiscarderProperty>
+      <strategy class="hudson.tasks.LogRotator">
+        <daysToKeep>90</daysToKeep>
+        <numToKeep>-1</numToKeep>
+        <artifactDaysToKeep>-1</artifactDaysToKeep>
+        <artifactNumToKeep>-1</artifactNumToKeep>
+      </strategy>
+    </jenkins.model.BuildDiscarderProperty>
     {% if variables.github == "True" %}
     <com.coravy.hudson.plugins.github.GithubProjectProperty>
       <projectUrl>{{ variables.GITHUB_URL }}</projectUrl>
diff --git a/jenkins/build_defs/bazel-job-PR.xml.tpl b/jenkins/build_defs/bazel-job-PR.xml.tpl
index 997209e..df1737c 100644
--- a/jenkins/build_defs/bazel-job-PR.xml.tpl
+++ b/jenkins/build_defs/bazel-job-PR.xml.tpl
@@ -7,6 +7,14 @@
     {% if variables.RUN_SEQUENTIAL == "true" %}
     <org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/>
     {% endif %}
+    <jenkins.model.BuildDiscarderProperty>
+      <strategy class="hudson.tasks.LogRotator">
+        <daysToKeep>90</daysToKeep>
+        <numToKeep>-1</numToKeep>
+        <artifactDaysToKeep>-1</artifactDaysToKeep>
+        <artifactNumToKeep>-1</artifactNumToKeep>
+      </strategy>
+    </jenkins.model.BuildDiscarderProperty>
     <com.coravy.hudson.plugins.github.GithubProjectProperty>
       <projectUrl>{{ variables.GITHUB_URL }}</projectUrl>
     </com.coravy.hudson.plugins.github.GithubProjectProperty>
diff --git a/jenkins/build_defs/bazel-job.xml.tpl b/jenkins/build_defs/bazel-job.xml.tpl
index b6073d5..7cd3169 100644
--- a/jenkins/build_defs/bazel-job.xml.tpl
+++ b/jenkins/build_defs/bazel-job.xml.tpl
@@ -7,6 +7,14 @@
     {% if variables.RUN_SEQUENTIAL == "true" %}
     <org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/>
     {% endif %}
+    <jenkins.model.BuildDiscarderProperty>
+      <strategy class="hudson.tasks.LogRotator">
+        <daysToKeep>90</daysToKeep>
+        <numToKeep>-1</numToKeep>
+        <artifactDaysToKeep>-1</artifactDaysToKeep>
+        <artifactNumToKeep>-1</artifactNumToKeep>
+      </strategy>
+    </jenkins.model.BuildDiscarderProperty>
     {% if variables.github == "True" %}
     <com.coravy.hudson.plugins.github.GithubProjectProperty>
       <projectUrl>{{ variables.GITHUB_URL }}</projectUrl>
diff --git a/jenkins/jobs/CR-global.xml.tpl b/jenkins/jobs/CR-global.xml.tpl
index 65ad55b..543693e 100644
--- a/jenkins/jobs/CR-global.xml.tpl
+++ b/jenkins/jobs/CR-global.xml.tpl
@@ -9,6 +9,14 @@
       <projectUrl>https://github.com/bazelbuild/bazel/</projectUrl>
       <displayName></displayName>
     </com.coravy.hudson.plugins.github.GithubProjectProperty>
+    <jenkins.model.BuildDiscarderProperty>
+      <strategy class="hudson.tasks.LogRotator">
+        <daysToKeep>90</daysToKeep>
+        <numToKeep>-1</numToKeep>
+        <artifactDaysToKeep>-1</artifactDaysToKeep>
+        <artifactNumToKeep>-1</artifactNumToKeep>
+      </strategy>
+    </jenkins.model.BuildDiscarderProperty>
     <hudson.model.ParametersDefinitionProperty>
       <parameterDefinitions>
         <hudson.model.StringParameterDefinition>
diff --git a/jenkins/jobs/global.xml.tpl b/jenkins/jobs/global.xml.tpl
index 1fbf5ef..40e66a2 100644
--- a/jenkins/jobs/global.xml.tpl
+++ b/jenkins/jobs/global.xml.tpl
@@ -9,6 +9,14 @@
       <projectUrl>https://github.com/bazelbuild/bazel/</projectUrl>
       <displayName></displayName>
     </com.coravy.hudson.plugins.github.GithubProjectProperty>
+    <jenkins.model.BuildDiscarderProperty>
+      <strategy class="hudson.tasks.LogRotator">
+        <daysToKeep>90</daysToKeep>
+        <numToKeep>-1</numToKeep>
+        <artifactDaysToKeep>-1</artifactDaysToKeep>
+        <artifactNumToKeep>-1</artifactNumToKeep>
+      </strategy>
+    </jenkins.model.BuildDiscarderProperty>
     <hudson.model.ParametersDefinitionProperty>
       <parameterDefinitions>
         <hudson.model.StringParameterDefinition>
diff --git a/jenkins/jobs/install-bazel.xml.tpl b/jenkins/jobs/install-bazel.xml.tpl
index 8ad10b0..ceeffca 100644
--- a/jenkins/jobs/install-bazel.xml.tpl
+++ b/jenkins/jobs/install-bazel.xml.tpl
@@ -5,6 +5,13 @@
   <keepDependencies>false</keepDependencies>
   <properties>
     <org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/>
+    <jenkins.model.BuildDiscarderProperty>
+      <strategy class="hudson.tasks.LogRotator">
+        <daysToKeep>-1</daysToKeep>
+        <numToKeep>25</numToKeep>
+        <artifactDaysToKeep>-1</artifactDaysToKeep>
+        <artifactNumToKeep>-1</artifactNumToKeep>
+      </strategy>
   </properties>
   <definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition">
     <script>{{ imports['//jenkins/jobs:install-bazel.groovy'] }}</script>
diff --git a/jenkins/jobs/jobs-Bazel-Benchmark.xml.tpl b/jenkins/jobs/jobs-Bazel-Benchmark.xml.tpl
index 70af478..bb3a6d2 100644
--- a/jenkins/jobs/jobs-Bazel-Benchmark.xml.tpl
+++ b/jenkins/jobs/jobs-Bazel-Benchmark.xml.tpl
@@ -22,6 +22,14 @@
     <com.coravy.hudson.plugins.github.GithubProjectProperty>
       <projectUrl>{{ variables.GITHUB_URL }}</projectUrl>
     </com.coravy.hudson.plugins.github.GithubProjectProperty>
+    <jenkins.model.BuildDiscarderProperty>
+      <strategy class="hudson.tasks.LogRotator">
+        <daysToKeep>90</daysToKeep>
+        <numToKeep>-1</numToKeep>
+        <artifactDaysToKeep>-1</artifactDaysToKeep>
+        <artifactNumToKeep>-1</artifactNumToKeep>
+      </strategy>
+    </jenkins.model.BuildDiscarderProperty>
   </properties>
   <scm class="hudson.plugins.git.GitSCM">
     <configVersion>2</configVersion>
diff --git a/jenkins/jobs/jobs-Bazel-Push-Benchmark-Output.xml.tpl b/jenkins/jobs/jobs-Bazel-Push-Benchmark-Output.xml.tpl
index 96bb9fc..62dbdd3 100644
--- a/jenkins/jobs/jobs-Bazel-Push-Benchmark-Output.xml.tpl
+++ b/jenkins/jobs/jobs-Bazel-Push-Benchmark-Output.xml.tpl
@@ -22,6 +22,14 @@
     <com.coravy.hudson.plugins.github.GithubProjectProperty>
       <projectUrl>{{ variables.GITHUB_URL }}</projectUrl>
     </com.coravy.hudson.plugins.github.GithubProjectProperty>
+    <jenkins.model.BuildDiscarderProperty>
+      <strategy class="hudson.tasks.LogRotator">
+        <daysToKeep>-1</daysToKeep>
+        <numToKeep>25</numToKeep>
+        <artifactDaysToKeep>-1</artifactDaysToKeep>
+        <artifactNumToKeep>-1</artifactNumToKeep>
+      </strategy>
+    </jenkins.model.BuildDiscarderProperty>
   </properties>
   <scm class="hudson.plugins.git.GitSCM">
     <configVersion>2</configVersion>