Created
July 4, 2017 16:09
-
-
Save rsvalerio/639501ccc2b1bc29e1b3b8f6d07fe040 to your computer and use it in GitHub Desktop.
Switch jenkins scm trigger from poll to webhook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hudson.model.* | |
import hudson.triggers.* | |
import com.cloudbees.jenkins.* | |
TriggerDescriptor SCM_TRIGGER_DESCRIPTOR = Hudson.instance.getDescriptorOrDie(SCMTrigger.class) | |
assert SCM_TRIGGER_DESCRIPTOR != null; | |
for(item in Hudson.instance.items) | |
{ | |
println("Working on project <$item.name>") | |
def trigger = item.getTriggers().get(SCM_TRIGGER_DESCRIPTOR) | |
if( trigger != null && trigger instanceof SCMTrigger && !(trigger instanceof GitHubPushTrigger)) | |
{ | |
println("> $trigger.spec") | |
println(SCM_TRIGGER_DESCRIPTOR.id) | |
def newTrigger = new GitHubPushTrigger() | |
newTrigger.job = item | |
item.removeTrigger(SCM_TRIGGER_DESCRIPTOR) | |
item.addTrigger(newTrigger) | |
} | |
else | |
{ | |
println "> Nothing to do" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment