jenkins-pipelinejenkins-pluginsrhel

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


Solution

  • 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:

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