forked from mark2b/hudson-notification-plugin
/
NotifyStep.java
130 lines (104 loc) · 3.29 KB
/
NotifyStep.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package com.tikal.hudson.plugins.notification;
import hudson.Extension;
import hudson.FilePath;
import hudson.Util;
import hudson.model.Run;
import hudson.model.TaskListener;
import org.eclipse.collections.impl.factory.Sets;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.steps.Step;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
import org.jenkinsci.plugins.workflow.steps.StepExecution;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import java.io.Serializable;
import java.util.Objects;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
public class NotifyStep extends Step implements Serializable {
private static final long serialVersionUID = -2818860651754465006L;
@CheckForNull
private String notes;
@CheckForNull
public String getNotes() {
return notes;
}
@DataBoundSetter
public void setNotes(@CheckForNull String notes) {
this.notes = Util.fixEmpty(notes);
}
@CheckForNull
private String phase = Phase.STARTED.name();
@CheckForNull
public String getPhase() {
return phase;
}
@DataBoundSetter
public void setPhase(@CheckForNull String phase) {
this.phase = Util.fixEmpty(phase);
}
@CheckForNull
private String loglines = "0";
@CheckForNull
public String getLoglines() {
return loglines;
}
@DataBoundSetter
public void setLoglines(@CheckForNull String loglines) {
this.loglines = Util.fixEmpty(loglines);
}
/**
* Creates a new instance of {@link NotifyStep}.
*/
@DataBoundConstructor
public NotifyStep() {
super();
// empty constructor required for Stapler
}
@Override
public StepExecution start(final StepContext context) {
return new Execution(context, this);
}
/**
* Actually performs the execution of the associated step.
*/
static class Execution extends StepExecution {
private static final long serialVersionUID = -2840020502160375407L;
private final NotifyStep notifyStep;
Execution(@Nonnull final StepContext context, final NotifyStep step) {
super(context);
notifyStep = step;
}
@Override
public boolean start() throws Exception {
String logLines = notifyStep.getLoglines();
Phase.NONE.handle(Objects.requireNonNull(getContext().get(Run.class)), getContext().get(TaskListener.class), System.currentTimeMillis(), true,
notifyStep.getNotes(), Integer.parseInt(logLines != null ? logLines : "0"), Phase.valueOf(notifyStep.getPhase()));
getContext().onSuccess(null);
return true;
}
}
/**
* Descriptor for this step: defines the context and the UI labels.
*/
@Extension
@SuppressWarnings("unused") // most methods are used by the corresponding jelly view
public static class Descriptor extends StepDescriptor {
@Override
public String getFunctionName() {
return "notifyEndpoints";
}
@Nonnull
@Override
public String getDisplayName() {
return Messages.Notify_DisplayName();
}
@Override
public Set<? extends Class<?>> getRequiredContext() {
return Sets.immutable.of(FilePath.class, FlowNode.class, Run.class, TaskListener.class)
.castToSet();
}
}
}