Skip to content

Commit 1dfa65c

Browse files
committed
[JENKINS-48523] config forms and refined help.html for the new conditionals
1 parent 4eede64 commit 1dfa65c

File tree

21 files changed

+546
-78
lines changed

21 files changed

+546
-78
lines changed

pipeline-model-definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/when/impl/ChangeRequestConditional.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import hudson.EnvVars;
2929
import hudson.Extension;
30+
import hudson.util.ListBoxModel;
3031
import jenkins.scm.api.SCMHead;
3132
import jenkins.scm.api.SCMHeadOrigin;
3233
import jenkins.scm.api.metadata.ContributorMetadataAction;
@@ -252,6 +253,10 @@ public static class DescriptorImpl extends DeclarativeStageConditionalDescriptor
252253
public Expression transformToRuntimeAST(@CheckForNull ModelASTWhenContent original) {
253254
return ASTParserUtils.transformWhenContentToRuntimeAST(original);
254255
}
256+
257+
public ListBoxModel doFillComparatorItems() {
258+
return Comparator.getSelectOptions(true, Comparator.EQUALS);
259+
}
255260
}
256261

257262
}

pipeline-model-definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/when/impl/TagConditional.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package org.jenkinsci.plugins.pipeline.modeldefinition.when.impl;
2727

2828
import hudson.Extension;
29+
import hudson.util.ListBoxModel;
2930
import org.apache.commons.lang.StringUtils;
3031
import org.apache.tools.ant.types.selectors.SelectorUtils;
3132
import org.codehaus.groovy.ast.expr.Expression;
@@ -93,5 +94,9 @@ public static class DescriptorImpl extends DeclarativeStageConditionalDescriptor
9394
public Expression transformToRuntimeAST(@CheckForNull ModelASTWhenContent original) {
9495
return ASTParserUtils.transformWhenContentToRuntimeAST(original);
9596
}
97+
98+
public ListBoxModel doFillComparatorItems() {
99+
return Comparator.getSelectOptions(true, Comparator.GLOB);
100+
}
96101
}
97102
}

pipeline-model-definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/when/utils/Comparator.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525

2626
package org.jenkinsci.plugins.pipeline.modeldefinition.when.utils;
2727

28+
import hudson.util.ListBoxModel;
2829
import org.apache.commons.lang.StringUtils;
2930
import org.apache.tools.ant.types.selectors.SelectorUtils;
31+
import org.jenkinsci.plugins.pipeline.modeldefinition.Messages;
32+
import org.jvnet.localizer.Localizable;
3033

3134
import javax.annotation.Nonnull;
3235
import java.io.File;
@@ -40,7 +43,7 @@ public enum Comparator {
4043
/**
4144
* ANT style "glob" pattern.
4245
*/
43-
GLOB {
46+
GLOB(Messages._Comparator_GLOB_DisplayName()) {
4447
@Override
4548
public boolean compare(@Nonnull String pattern, String actual) {
4649
actual = defaultIfBlank(actual, "");
@@ -54,7 +57,7 @@ public boolean compare(@Nonnull String pattern, String actual) {
5457
/**
5558
* Regular expression
5659
*/
57-
REGEXP {
60+
REGEXP(Messages._Comparator_REGEXP_DisplayName()) {
5861
@Override
5962
public boolean compare(@Nonnull String pattern, String actual) {
6063
actual = defaultIfBlank(actual, "");
@@ -65,14 +68,24 @@ public boolean compare(@Nonnull String pattern, String actual) {
6568
/**
6669
* String equals
6770
*/
68-
EQUALS {
71+
EQUALS(Messages._Comparator_EQUALS_DisplayName()) {
6972
@Override
7073
public boolean compare(@Nonnull String pattern, String actual) {
7174
actual = defaultIfBlank(actual, "");
7275
return actual.equals(pattern);
7376
}
7477
};
7578

79+
private final Localizable displayName;
80+
81+
private Comparator(Localizable displayName) {
82+
this.displayName = displayName;
83+
}
84+
85+
public Localizable getDisplayName() {
86+
return displayName;
87+
}
88+
7689
/**
7790
* Compare the two strings
7891
* @param pattern the pattern/value to check for
@@ -92,4 +105,20 @@ public static Comparator get(String name, Comparator defaultValue) {
92105
}
93106
return defaultValue;
94107
}
108+
109+
public static ListBoxModel getSelectOptions(boolean emptySelection, Comparator top) {
110+
ListBoxModel model = new ListBoxModel();
111+
if (emptySelection) {
112+
model.add("");
113+
}
114+
if (top != null) {
115+
model.add(top.getDisplayName().toString(), top.name());
116+
}
117+
for (Comparator comparator : Comparator.values()) {
118+
if (comparator != top) {
119+
model.add(comparator.getDisplayName().toString(), comparator.name());
120+
}
121+
}
122+
return model;
123+
}
95124
}

pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/Messages.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,8 @@ WhenConditionalValidator.changelog.missingParameter=Changelog is missing require
153153
WhenConditionalValidator.changelog.badPattern="{0}" is not a valid regular expression. {1}
154154

155155
ModelInterpreter.NoNodeContext=Attempted to execute a step that requires a node context while 'agent none' was specified. Be sure to specify your own 'node { ... }' blocks when using 'agent none'.
156+
157+
Comparator.GLOB.DisplayName=Glob
158+
Comparator.REGEXP.DisplayName=Regular Expression
159+
Comparator.EQUALS.DisplayName=Equals
160+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ The MIT License
4+
~
5+
~ Copyright (c) 2018, CloudBees, Inc.
6+
~
7+
~ Permission is hereby granted, free of charge, to any person obtaining a copy
8+
~ of this software and associated documentation files (the "Software"), to deal
9+
~ in the Software without restriction, including without limitation the rights
10+
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
~ copies of the Software, and to permit persons to whom the Software is
12+
~ furnished to do so, subject to the following conditions:
13+
~
14+
~ The above copyright notice and this permission notice shall be included in
15+
~ all copies or substantial portions of the Software.
16+
~
17+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
~ THE SOFTWARE.
24+
~
25+
-->
26+
<?jelly escape-by-default='true'?>
27+
<j:jelly xmlns:j="jelly:core">
28+
</j:jelly>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ The MIT License
4+
~
5+
~ Copyright (c) 2018, CloudBees, Inc.
6+
~
7+
~ Permission is hereby granted, free of charge, to any person obtaining a copy
8+
~ of this software and associated documentation files (the "Software"), to deal
9+
~ in the Software without restriction, including without limitation the rights
10+
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
~ copies of the Software, and to permit persons to whom the Software is
12+
~ furnished to do so, subject to the following conditions:
13+
~
14+
~ The above copyright notice and this permission notice shall be included in
15+
~ all copies or substantial portions of the Software.
16+
~
17+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
~ THE SOFTWARE.
24+
~
25+
-->
26+
<?jelly escape-by-default='true'?>
27+
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
28+
<f:entry field="comparator" title="Comparator">
29+
<f:select/>
30+
</f:entry>
31+
<f:entry field="id" title="Id">
32+
<f:textbox/>
33+
</f:entry>
34+
<f:entry field="target" title="Target">
35+
<f:textbox/>
36+
</f:entry>
37+
<f:entry field="branch" title="Branch">
38+
<f:textbox/>
39+
</f:entry>
40+
<f:entry field="fork" title="Fork">
41+
<f:textbox/>
42+
</f:entry>
43+
<f:entry field="url" title="Url">
44+
<f:textbox/>
45+
</f:entry>
46+
<f:entry field="title" title="Title">
47+
<f:textbox/>
48+
</f:entry>
49+
<f:entry field="author" title="Author">
50+
<f:textbox/>
51+
</f:entry>
52+
<f:entry field="authorDisplayName" title="Author Display name">
53+
<f:textbox/>
54+
</f:entry>
55+
<f:entry field="authorEmail" title="Author E-Mail">
56+
<f:textbox/>
57+
</f:entry>
58+
</j:jelly>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!--
2+
~ The MIT License
3+
~
4+
~ Copyright (c) 2018, CloudBees, Inc.
5+
~
6+
~ Permission is hereby granted, free of charge, to any person obtaining a copy
7+
~ of this software and associated documentation files (the "Software"), to deal
8+
~ in the Software without restriction, including without limitation the rights
9+
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
~ copies of the Software, and to permit persons to whom the Software is
11+
~ furnished to do so, subject to the following conditions:
12+
~
13+
~ The above copyright notice and this permission notice shall be included in
14+
~ all copies or substantial portions of the Software.
15+
~
16+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
~ THE SOFTWARE.
23+
~
24+
-->
25+
26+
<p>
27+
<strong>author</strong><br/>
28+
<code>CHANGE_AUTHOR</code>
29+
The author identity.
30+
</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!--
2+
~ The MIT License
3+
~
4+
~ Copyright (c) 2018, CloudBees, Inc.
5+
~
6+
~ Permission is hereby granted, free of charge, to any person obtaining a copy
7+
~ of this software and associated documentation files (the "Software"), to deal
8+
~ in the Software without restriction, including without limitation the rights
9+
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
~ copies of the Software, and to permit persons to whom the Software is
11+
~ furnished to do so, subject to the following conditions:
12+
~
13+
~ The above copyright notice and this permission notice shall be included in
14+
~ all copies or substantial portions of the Software.
15+
~
16+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
~ THE SOFTWARE.
23+
~
24+
-->
25+
26+
<p>
27+
<strong>authorDisplayName</strong><br/>
28+
<code>CHANGE_AUTHOR_DISPLAY_NAME</code>
29+
The display name of the author, may be same as username depending on platform.
30+
</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!--
2+
~ The MIT License
3+
~
4+
~ Copyright (c) 2018, CloudBees, Inc.
5+
~
6+
~ Permission is hereby granted, free of charge, to any person obtaining a copy
7+
~ of this software and associated documentation files (the "Software"), to deal
8+
~ in the Software without restriction, including without limitation the rights
9+
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
~ copies of the Software, and to permit persons to whom the Software is
11+
~ furnished to do so, subject to the following conditions:
12+
~
13+
~ The above copyright notice and this permission notice shall be included in
14+
~ all copies or substantial portions of the Software.
15+
~
16+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
~ THE SOFTWARE.
23+
~
24+
-->
25+
26+
<p>
27+
<strong>authorEmail</strong><br/>
28+
<code>CHANGE_AUTHOR_EMAIL</code>
29+
The author's e-mail.
30+
</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!--
2+
~ The MIT License
3+
~
4+
~ Copyright (c) 2018, CloudBees, Inc.
5+
~
6+
~ Permission is hereby granted, free of charge, to any person obtaining a copy
7+
~ of this software and associated documentation files (the "Software"), to deal
8+
~ in the Software without restriction, including without limitation the rights
9+
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
~ copies of the Software, and to permit persons to whom the Software is
11+
~ furnished to do so, subject to the following conditions:
12+
~
13+
~ The above copyright notice and this permission notice shall be included in
14+
~ all copies or substantial portions of the Software.
15+
~
16+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
~ THE SOFTWARE.
23+
~
24+
-->
25+
26+
<p>
27+
<strong>branch</strong><br/>
28+
<code>CHANGE_BRANCH</code>
29+
The name of the actual head on the source control system which may or may not be different from
30+
<code>BRANCH_NAME</code>. For example in GitHub or Bitbucket this would have the name of the origin branch
31+
whereas <code>BRANCH_NAME</code> would be something like <code>PR-24</code>.
32+
</p>

0 commit comments

Comments
 (0)