Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discard old build in multi-branch pipeline job, doesn't really delete builds from server

I have multi-branch pipeline job in Jenkins:

http://illinXXXX:XXXX/job/OC/configure

and I checked the option for Discard old builds as below:

Discard old builds

I would have expected, that each new run after this change, it will delete old build from the server for each Repository inside that pipeline. however, I see all builds are still there, which causing me a File system issue. Jenkins link:

http://illinXXX:XXXX/job/OC/job/productconfigurator-ms/job/master/

From server:

jenkins@XXXXX:jenkins/jenkins-production/jobs/OC/jobs/productconfigurator-ms/branches/master/builds>

I see builds from 541 to 1039

Jenkins ver. 2.176.1

like image 579
arielma Avatar asked Jan 01 '23 09:01

arielma


2 Answers

The interface you pasted is for the Orphaned items. Orphaned items refer to deleted branches, where no Jenkinsfile is available.

For the Multibranch pipeline, the instructions to build each branch are inside that branch's Jenkinsfile. This is where you need to define these limits.

Use the following in your Jenkinsfile (from above, in master branch):

options {
        buildDiscarder(logRotator(numToKeepStr: "100"))
}

Make sure to use string (as in "100") and not number (as in 100).

Parameters:

  • daysToKeepStr: history is only kept up to this many days.
  • numToKeepStr: only this many build logs are kept.
  • artifactDaysToKeepStr: artifacts are only kept up to this many days.
  • artifactNumToKeepStr: only this many builds have their artifacts kept.

You may need to run your master pipeline manually once for it to work.

like image 129
MaratC Avatar answered Jan 04 '23 15:01

MaratC


This is the equivalent of scripted-pipeline:

node('some-label') {
        properties([
                buildDiscarder(
                        logRotator(
                                artifactDaysToKeepStr: "10",
                                artifactNumToKeepStr: "50",
                                daysToKeepStr: "10",
                                numToKeepStr: "50")
                )
        ])

        stage('Maven Compile') {
        }

        stage('Some other steps') {
        }
   
}
like image 45
xbmono Avatar answered Jan 04 '23 15:01

xbmono