/
SampleConfiguration.java
70 lines (57 loc) · 1.84 KB
/
SampleConfiguration.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 io.jenkins.plugins.sample;
import hudson.Extension;
import hudson.ExtensionList;
import hudson.util.FormValidation;
import jenkins.model.GlobalConfiguration;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
/**
* Example of Jenkins global configuration.
*/
@Extension
public class SampleConfiguration extends GlobalConfiguration {
/** @return the singleton instance */
public static SampleConfiguration get() {
return ExtensionList.lookupSingleton(SampleConfiguration.class);
}
private String label;
private String anotherLabel;
public SampleConfiguration() {
// When Jenkins is restarted, load any saved configuration from disk.
load();
}
/** @return the currently configured label, if any */
public String getLabel() {
return label;
}
/**
* Together with {@link #getLabel}, binds to entry in {@code config.jelly}.
* @param label the new value of this field
*/
@DataBoundSetter
public void setLabel(String label) {
this.label = label;
save();
}
public String getAnotherLabel() {
return anotherLabel;
}
@DataBoundSetter
public void setAnotherLabel(String anotherLabel) {
this.anotherLabel = anotherLabel;
save();
}
public FormValidation doCheckLabel(@QueryParameter String value) {
if (StringUtils.isEmpty(value)) {
return FormValidation.warning("Please specify a label.");
}
return FormValidation.ok("Label is alright");
}
public FormValidation doCheckAnotherLabel(@QueryParameter String value) {
if (value.contains("fail")) {
return FormValidation.warning("Wrong label");
}
return FormValidation.ok("Label is alright");
}
}