Merge pull request #7 from DABSquared/selective_trigger

Selective trigger
This commit is contained in:
bassrock 2014-08-05 10:04:38 -07:00
commit cdfc21d2db
2 changed files with 92 additions and 70 deletions

View File

@ -42,14 +42,25 @@ import com.dabsquared.gitlabjenkins.GitLabPushRequest.Commit;
* @author Daniel Brooks
*/
public class GitLabPushTrigger extends Trigger<AbstractProject<?, ?>> {
private boolean triggerOnPush = true;
private boolean triggerOnMergeRequest = true;
@DataBoundConstructor
public GitLabPushTrigger() {
public GitLabPushTrigger(boolean triggerOnPush, boolean triggerOnMergeRequest) {
this.triggerOnPush = triggerOnPush;
this.triggerOnMergeRequest = triggerOnMergeRequest;
}
public boolean getTriggerOnPush() {
return triggerOnPush;
}
public boolean getTriggerOnMergeRequest() {
return triggerOnMergeRequest;
}
public void onPost(final GitLabPushRequest req) {
if (triggerOnPush) {
getDescriptor().queue.execute(new Runnable() {
public void run() {
@ -103,8 +114,10 @@ public class GitLabPushTrigger extends Trigger<AbstractProject<?, ?>> {
});
}
}
public void onPost(final GitLabMergeRequest req) {
if (triggerOnMergeRequest) {
getDescriptor().queue.execute(new Runnable() {
public void run() {
LOGGER.log(Level.INFO, "{0} triggered.", job.getName());
@ -148,6 +161,7 @@ public class GitLabPushTrigger extends Trigger<AbstractProject<?, ?>> {
});
}
}
@Override
public DescriptorImpl getDescriptor() {

View File

@ -0,0 +1,8 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry title="Build on Push Events" field="triggerOnPush">
<f:checkbox default="true" />
</f:entry>
<f:entry title="Build on Merge Request Events" field="triggerOnMergeRequest">
<f:checkbox default="true" />
</f:entry>
</j:jelly>