If you're using the Jenkins Job DSL to create a job
or pipelineJob
, you can use any of the following formats to add the discard builds configuration to your job:
Option 1
This option modifies the XML structure of the job directly.
pipelineJob { configure { it / 'properties' / 'jenkins.model.BuildDiscarderProperty' { strategy {'daysToKeep'('7')'numToKeep'('10')'artifactDaysToKeep'('-1')'artifactNumToKeep'('-1') } } }}
Option 2
pipelineJob { logRotator(7, 10, -1, -1)}
Option 3
pipelineJob { logRotator { numToKeep(10) daysToKeep(7) artifactNumToKeep(-1) artifactDaysToKeep(-1) }}
See the following links for additional details: