I'm using a Jenkinsfile with a Scripted Pipeline.
I would like to modify the buildDiscarder
option for this pipeline, but I can't get it working.
https://jenkins.io/doc/book/pipeline/syntax/#options
How to define pipeline options in a scripted pipeline?
You can't use options
as that is a specific piece of the Declarative Pipeline feature set.
For the multibranch-style builds you should use the properties
step. The Snippet Generator can help you find the correct syntax to help build out pieces of your Jenkinsfile. For example, in this case you would use the buildDiscarder
symbol that resolves to that configuration option.
properties(
[
buildDiscarder(
logRotator(
daysToKeepStr: '7',
numToKeepStr: '25'
)
)
]
)
The properties
step will be evaluated when your Jenkinsfile
is executed, so that is when the configuration will be effective. I tend to put the properties
at the top as a "best practice".
See the full options on your instance's Snippet Generator for the other things you can keep (such as artifacts).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With