Groovy syntax to retrieve a multibranch pipeline's build trigger property
Trying to loop through all multi branch pipeline jobs and getting the Build Trigger property Build Periodically.
I'm looking through APIs and the Jenkins GitHub but can't find the methods of org.jenkinsci.plugins.workflow.job.WorkflowJob to get this property.
I also need to set these properties if they are not set, so a link to an API would be helpful.
-
All the Pipeline projects inside Organization Folder / Multi-branch Pipelines are automatically generated and should not be modified manually.
The way to set properties and triggers of such Pipelines is from the Pipelines themselves, using the `properties` step in scripted or declarative directives.
0 -
Thanks @Denys. My aim is to create a cron job to check mutli-branch pipelines and enforce a standard minimum "build periodically" trigger so that some jobs do not build too many times.
I'm able to grab the schedule for jobs like this:
List keys = new ArrayList(job.getTriggers().keySet());
for (int i = 0; i < keys.size(); i++) {
Object obj = keys.get(i);
if(obj.getDisplayName().contains("Build periodically")) {
println job.fullName + "," + job.getTriggers().get(keys.get(i)).spec
}
}0 -
Hello Brandon,
You can use a script like the following to check the cron trigger of all multibranch jobs in your instance:
import jenkins.model.Jenkins
Jenkins.instanceOrNull.getAllItems(com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.class)
.each { org ->
println "${org.fullDisplayName}"
hudson.triggers.Trigger periodicFolderTrigger = org.getTriggers().find { triggerEntry ->
triggerEntry.key instanceof com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger.DescriptorImpl
}?.getValue()
if(periodicFolderTrigger != null) {
println " PeriodicFolderTrigger { interval: ${periodicFolderTrigger.getInterval()}, spec: ${periodicFolderTrigger.getSpec()} }"
} else {
println " No PeriodicFolderTrigger"
}
}
returnRegards,
0
Please sign in to leave a comment.
Comments
3 comments