Skip to content

Commit 7da5f65

Browse files
committedJul 30, 2024··
Level 3
1 parent 0cf6b8c commit 7da5f65

File tree

9 files changed

+71
-3
lines changed

9 files changed

+71
-3
lines changed
 

‎.DS_Store

8 KB
Binary file not shown.

‎src/.DS_Store

6 KB
Binary file not shown.

‎src/main/.DS_Store

6 KB
Binary file not shown.

‎src/main/java/.DS_Store

6 KB
Binary file not shown.

‎src/main/java/io/.DS_Store

6 KB
Binary file not shown.

‎src/main/java/io/jenkins/.DS_Store

6 KB
Binary file not shown.
6 KB
Binary file not shown.

‎src/main/java/io/jenkins/plugins/sample/SampleConfiguration.java

+59-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import hudson.Extension;
44
import hudson.ExtensionList;
55
import hudson.util.FormValidation;
6+
import hudson.util.Secret;
67
import jenkins.model.GlobalConfiguration;
78
import org.apache.commons.lang.StringUtils;
89
import org.kohsuke.stapler.DataBoundSetter;
@@ -21,6 +22,54 @@ public static SampleConfiguration get() {
2122

2223
private String label;
2324
private String description;
25+
private String url;
26+
private String userName;
27+
private Secret password;
28+
private boolean optionalBlock;
29+
30+
public boolean isOptionalBlock() {
31+
return optionalBlock;
32+
}
33+
34+
@DataBoundSetter
35+
public void setOptionalBlock(boolean optionalBlock) {
36+
this.optionalBlock = optionalBlock;
37+
save();
38+
}
39+
40+
public Secret getPassword() {
41+
return password;
42+
}
43+
44+
@DataBoundSetter
45+
public void setPassword(Secret password) {
46+
this.password = password;
47+
save();
48+
}
49+
50+
51+
52+
public String getUserName() {
53+
return userName;
54+
}
55+
56+
@DataBoundSetter
57+
public void setUserName(String userName) {
58+
this.userName = userName;
59+
save();
60+
}
61+
62+
63+
64+
public String getUrl() {
65+
return url;
66+
}
67+
68+
@DataBoundSetter
69+
public void setUrl(String url) {
70+
this.url = url;
71+
save();
72+
}
2473

2574
public String getDescription() {
2675
return description;
@@ -55,8 +104,8 @@ public void setLabel(String label) {
55104
public FormValidation doCheckLabel(@QueryParameter String value) {
56105
if (StringUtils.isEmpty(value)) {
57106
return FormValidation.warning("Please specify a label.");
58-
}else if (!value.matches("[a-zA-Z]")) {
59-
return FormValidation.error("Only lowercase and uppercase ans spaces are allowed");
107+
}if (!value.matches("[a-zA-Z ]+")) {
108+
return FormValidation.warning("Name can only contain letters and spaces.");
60109
}
61110
return FormValidation.ok();
62111
}
@@ -66,5 +115,13 @@ public FormValidation doCheckDescription(@QueryParameter String value) {
66115
}
67116
return FormValidation.ok();
68117
}
118+
public FormValidation doCheckUserName(@QueryParameter String value) {
119+
if(StringUtils.isEmpty(value)) {
120+
return FormValidation.warning("Please specify username");
121+
} if (!value.matches("[a-zA-Z]+")) {
122+
return FormValidation.warning("UserName can only contain letters.");
123+
}
124+
return FormValidation.ok();
125+
}
69126

70127
}

‎src/main/resources/io/jenkins/plugins/sample/SampleConfiguration/config.jelly

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@
22
<?jelly escape-by-default='true'?>
33
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
44
<f:section title="${%Sample Plugin}">
5-
<f:entry field="label" title="${%Label}">
5+
<f:entry field="label" title="${%Name}">
66
<f:textbox/>
77
</f:entry>
88
<f:entry field="description" title="${%Description}">
99
<f:textarea/>
1010
</f:entry>
11+
<f:optionalBlock name="optionalBlock" title="${%Enable Connection}">
12+
<f:entry field="url" title="${%URL}">
13+
<f:textbox/>
14+
</f:entry>
15+
<f:entry field="username" title="${%Username}">
16+
<f:textbox/>
17+
</f:entry>
18+
<f:entry field="password" title="${%Password}">
19+
<f:password/>
20+
</f:entry>
21+
</f:optionalBlock>
1122
</f:section>
1223
</j:jelly>

0 commit comments

Comments
 (0)
Please sign in to comment.