Skip to content

Instantly share code, notes, and snippets.

@duffn
Created July 19, 2019 13:36
Show Gist options
  • Save duffn/7adfd5fb64cfe6aa0eae9919fe33dc03 to your computer and use it in GitHub Desktop.
Save duffn/7adfd5fb64cfe6aa0eae9919fe33dc03 to your computer and use it in GitHub Desktop.
Update a Scan Repository Trigger in a Jenkins GitHub Cloudbees folder
// Update the PeriodicFolderTrigger of each job inside of a Cloudbees folder.
// Useful for updating individual repos as you cannot do this through the UI.
// https://stackoverflow.com/questions/57077851/jenkins-github-plugin-scan-organization-triggers
import com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger
import jenkins.model.Jenkins
import jenkins.branch.OrganizationFolder
println "Multibranch Items\n-------"
Jenkins.instance.getAllItems(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject.class).each { it.triggers
.findAll { k,v -> v instanceof com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger }
.each { k,v -> setInterval(it) }
}
def setInterval(folder) {
println "[INFO] : Updating ${folder.name}... "
folder.getTriggers().find {triggerEntry ->
def key = triggerEntry.key
if (key instanceof PeriodicFolderTrigger.DescriptorImpl){
println "[INFO] : Current interval : " + triggerEntry.value.getInterval()
// Valid intervals are here:
// https://github.com/jenkinsci/cloudbees-folder-plugin/blob/master/src/main/java/com/cloudbees/hudson/plugins/folder/computed/PeriodicFolderTrigger.java#L261-L278
def newInterval = new PeriodicFolderTrigger("28d")
folder.addTrigger(newInterval)
folder.save()
println "[INFO] : New interval : " + newInterval.getInterval()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment