'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:
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 1:[1]
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.
Solution 2:[2]
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') {
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | MaratC |
Solution 2 | xbmono |