Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.