2

I have used the Blue Ocean plugin to create a Jenkins job that automatically uses the Jenkinsfile (declarative pipeline) to build and report the status back to GitHub. That all works fine.

The issue I have is that I cannot get old builds deleted. The job shows as a repository and I have configured it to keep a maximum of 5 builds. But I noticed that the branches indexed, including the master branch, also have their own configuration. I tried setting up the old builds deletion but there’s no save button! I thought this was because the configuration propagates from the repository to the branches, but it has no effect. How can I get this to work?

Nagev
  • 580
  • 1
  • 6
  • 10

2 Answers2

4

Certain job properties are adjusted using directives in Jenkinsfiles and not the configuration in the web UI. In your Jenkinsfile:

properties([
  // only keep 25 builds to prevent disk usage from growing out of control
  buildDiscarder(
    logRotator(
      artifactDaysToKeepStr: '', 
      artifactNumToKeepStr: '', 
      daysToKeepStr: '', 
      numToKeepStr: '25',
    ),
  ),
])

You may of course adjust the various parameters to suit your needs.

jayhendren
  • 1,014
  • 5
  • 12
  • Now it makes sense that the GUI view is read-only for branches, I see it reflects the properties set in their respective Jenkinsfiles. This is probably an effect of the [multi-branch plugin](https://jenkins.io/doc/pipeline/steps/workflow-multibranch/#-properties-%20set%20job%20properties). I placed the properties snippet above the pipeline directive on the declarative pipeline. – Nagev Aug 21 '18 at 12:11
1

Unsure which Jenkins version brought the update, but the syntax has changed. Modifying jayhendren's example:

options {
  // only keep 25 builds to prevent disk usage from growing out of control
  buildDiscarder(
    logRotator(
      artifactDaysToKeepStr: '', 
      artifactNumToKeepStr: '', 
      daysToKeepStr: '', 
      numToKeepStr: '25',
    ),
  ),
}
Bryan S
  • 11
  • 1
  • 2
    It appears that both [syntaxes](https://jenkins.io/doc/book/pipeline/syntax/#compare) can be used: jayhendren's as a scripted pipeline and @Bryan's as a declarative one ([How do I set discard old builds for a Multi Branch Pipeline Job? – CloudBees Support](https://support.cloudbees.com/hc/en-us/articles/115000237071-How-do-I-set-discard-old-builds-for-a-Multi-Branch-Pipeline-Job)) – evgeny9 Apr 23 '20 at 16:58