Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@oillio
Created June 14, 2016 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oillio/14cb6621877ecfb3a1d711e0f31ace90 to your computer and use it in GitHub Desktop.
Save oillio/14cb6621877ecfb3a1d711e0f31ace90 to your computer and use it in GitHub Desktop.
public class TriggerStep extends AbstractStepImpl {
private final String spec;
@DataBoundConstructor
public TriggerStep(String spec) {
this.spec = spec;
}
public String getSpec() {
return spec;
}
public static class Execution extends AbstractSynchronousStepExecution<Void> {
private static final long serialVersionUID = 1L;
@Inject
transient TriggerStep step;
@StepContextParameter
transient Run<?,?> build;
@Override
protected Void run() throws Exception {
Job<?,?> parent = build.getParent();
if(parent instanceof WorkflowJob) {
WorkflowJob job = (WorkflowJob) parent;
job.addTrigger(new SCMTrigger(step.getSpec()));
job.save();
} else {
throw new AbortException("cannot apply trigger to job of type " + parent.getClass().getSimpleName());
}
return null;
}
}
@Extension
public static class DiscriptorImpl extends AbstractStepDescriptorImpl {
public DiscriptorImpl() {
super(Execution.class);
}
@Override
public String getFunctionName() {
return "scmTrigger";
}
@Override
public String getDisplayName() {
return "Set an SCM Trigger for this project.";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment