Skip to content

Commit

Permalink
JENKINS-73698 Add Setter
Browse files Browse the repository at this point in the history
  • Loading branch information
aendter committed Sep 12, 2024
1 parent fd13c35 commit 52671a9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ For more information see the [homepage].

# Change Log

##### Version 0.0.13 (September 12, 2024)

- Small bugfix - Node Name parameter not stored in Freestyle jobs [JENKINS-73698](https://issues.jenkins.io/browse/JENKINS-73698)

##### Version 0.0.12 (July 23, 2024)

- Small bugfix - After adding the parameter to a job, other parameters/steps can't be added [JENKINS-73159](https://issues.jenkins.io/browse/JENKINS-73159)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</description>

<properties>
<jenkins.version>2.420</jenkins.version>
<jenkins.version>2.430</jenkins.version>
</properties>

<licenses>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jenkinsci.Symbol;
import org.jenkinsci.remoting.RoleChecker;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

Expand Down Expand Up @@ -70,7 +71,7 @@ public FormValidation doCheckName(@QueryParameter final String name) throws IOEx
return FormValidation.ok();
}

public FormValidation doCheckPath(@QueryParameter final String path, @QueryParameter final String nodeName) throws IOException, InterruptedException {
public FormValidation doCheckPath(@QueryParameter final String path, @QueryParameter final String selectedNodeName) throws IOException, InterruptedException {
if (StringUtils.isBlank(path)) {
return FormValidation.error(Messages.FileSystemListParameterDefinition_PathCanNotBeEmpty());
}
Expand All @@ -80,7 +81,7 @@ public FormValidation doCheckPath(@QueryParameter final String path, @QueryParam
VirtualChannel channel = null;


if (nodeName==null || nodeName.equals(MASTER)) {
if (selectedNodeName==null || selectedNodeName.equals(MASTER)) {
File dir = new File(path);
if (!dir.exists()) {
return FormValidation.error(Messages.FileSystemListParameterDefinition_PathDoesntExist(), path);
Expand All @@ -95,8 +96,8 @@ public FormValidation doCheckPath(@QueryParameter final String path, @QueryParam
} else {


if (!nodeName.trim().isEmpty() && instance != null) {
computer = instance.getComputer(nodeName);
if (!selectedNodeName.trim().isEmpty() && instance != null) {
computer = instance.getComputer(selectedNodeName);

Check warning on line 100 in src/main/java/alex/jenkins/plugins/FileSystemListParameterDefinition.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 84-100 are not covered by tests
if (computer != null) {
channel = computer.getChannel();
}
Expand Down Expand Up @@ -141,7 +142,7 @@ private FormValidation checkRegex(String regex) {
}


private String nodeName;
private String selectedNodeName;
private String path;
private String selectedType;
private String formSelectType;
Expand All @@ -159,15 +160,15 @@ private FormValidation checkRegex(String regex) {
* @param description
*/
@DataBoundConstructor
public FileSystemListParameterDefinition(String name, String description, String nodeName, String path, String defaultValue, String selectedType,
public FileSystemListParameterDefinition(String name, String description, String selectedNodeName, String path, String defaultValue, String selectedType,
String formSelectType, String regexIncludePattern, String regexExcludePattern, boolean sortByLastModified,
boolean sortReverseOrder, boolean includePathInValue) {

super(name);

super.setDescription(description);

this.nodeName = nodeName;
this.selectedNodeName = selectedNodeName;
this.path = Util.fixNull(path);
this.defaultValue = defaultValue;
this.selectedType = selectedType;
Expand Down Expand Up @@ -241,8 +242,8 @@ public List<String> getFsObjectsList() throws Exception {
Computer computer = null;
VirtualChannel channel = null;
Jenkins instance = Jenkins.getInstanceOrNull();
if (getNodeName() != null && !getNodeName().trim().isEmpty() && instance != null) {
computer = instance.getComputer(getNodeName());
if (getSelectedNodeName() != null && !getSelectedNodeName().trim().isEmpty() && instance != null) {

Check warning on line 245 in src/main/java/alex/jenkins/plugins/FileSystemListParameterDefinition.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 245 is only partially covered, 3 branches are missing
computer = instance.getComputer(getSelectedNodeName());
if (computer != null) {
channel = computer.getChannel();
}
Expand Down Expand Up @@ -480,10 +481,10 @@ public static List<String> getNodeNames() {
// add master
list.add(MASTER);
for (Node node : nodes) {
String nodeName = node.getNodeName();
if (StringUtils.isNotBlank(nodeName)) {
LOGGER.finest("# add " + nodeName);
list.add(nodeName);
String tmpNodeName = node.getNodeName();
if (StringUtils.isNotBlank(tmpNodeName)) {
LOGGER.finest("# add " + tmpNodeName);
list.add(tmpNodeName);

Check warning on line 487 in src/main/java/alex/jenkins/plugins/FileSystemListParameterDefinition.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 246-487 are not covered by tests
}
}

Expand Down Expand Up @@ -527,10 +528,15 @@ public String getRegexExcludePattern() {
return regexExcludePattern;
}

public String getNodeName() {
return nodeName;
public String getSelectedNodeName() {
return selectedNodeName;
}

@DataBoundSetter
public String setSelectedNodeName() {
return selectedNodeName;

Check warning on line 537 in src/main/java/alex/jenkins/plugins/FileSystemListParameterDefinition.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 537 is not covered by tests
}

public String getDefaultValue() {
return defaultValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
<f:textarea name="parameter.description" value="${instance.description}" codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}" previewEndpoint="/markupFormatter/previewDescription" />
</f:entry>

<f:entry title="NodeName" field="selected-nodeName">
<select name="selected-nodeName" >
<f:entry title="NodeName" field="selectedNodeName">
<select name="selectedNodeName" >
<j:invokeStatic className="alex.jenkins.plugins.FileSystemListParameterDefinition" method="getNodeNames" var="nodeList" />
<j:forEach var="node" items="${nodeList}" varStatus="loop">
<j:choose>
<j:when test="${instance.selected-nodeName.equals(node)}">
<j:when test="${instance.selectedNodeName.equals(node)}">
<option value="${node}" selected="selected">${node}</option>
</j:when>
<j:otherwise>
Expand Down

0 comments on commit 52671a9

Please sign in to comment.