-
Notifications
You must be signed in to change notification settings - Fork 34
/
SqsBuildTrigger.java
70 lines (54 loc) · 1.7 KB
/
SqsBuildTrigger.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.base2services.jenkins;
import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.Item;
import hudson.model.Job;
import hudson.triggers.Trigger;
import hudson.triggers.TriggerDescriptor;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import java.util.ArrayList;
import java.util.List;
/**
* Triggers a build when we receive a message from SQS.
*
* @author aaronwalker
*/
public class SqsBuildTrigger extends Trigger<Job> {
@DataBoundConstructor
public SqsBuildTrigger() {
}
@Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl) super.getDescriptor();
}
@Extension
public static class DescriptorImpl extends TriggerDescriptor {
private volatile List<SqsProfile> sqsProfiles = new ArrayList<>();
public DescriptorImpl() {
load();
}
@Override
public boolean isApplicable(Item item) {
return item instanceof AbstractProject;
}
@Override
public String getDisplayName() {
return "Build when a message is published to an SQS Queue";
}
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
JSONObject sqs = json.getJSONObject("sqsProfiles");
sqsProfiles = req.bindJSONToList(SqsProfile.class, sqs);
save();
return true;
}
public static DescriptorImpl get() {
return Trigger.all().get(DescriptorImpl.class);
}
public List<SqsProfile> getSqsProfiles() {
return sqsProfiles;
}
}
}