Skip to content

Commit

Permalink
Merge pull request #302 from duemir/JENKINS-61474
Browse files Browse the repository at this point in the history
JENKINS-61474 Improve null safety of the tool step
  • Loading branch information
jtnord authored Mar 5, 2024
2 parents 2e7111a + 936b400 commit 257ae6b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static final class Execution extends SynchronousNonBlockingStepExecution<
continue;
}
for (ToolInstallation tool : desc.getInstallations()) {
if (tool.getName().equals(name)) {
if (name.equals(tool.getName())) {
if (tool instanceof NodeSpecific) {
tool = (ToolInstallation) ((NodeSpecific<?>) tool).forNode(getContext().get(Node.class), getContext().get(TaskListener.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;
import org.jvnet.hudson.test.ToolInstallations;
Expand Down Expand Up @@ -120,6 +121,21 @@ public class ToolStepTest {
r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}

@Issue("JENKINS-61474") @Test public void toolWithoutName() throws Exception {
File toolHome = folder.newFolder("mockTools");
MockToolWithSymbol misconfiguredTool = new MockToolWithSymbol(null, toolHome.getAbsolutePath(), JenkinsRule.NO_PROPERTIES);
MockToolWithSymbol tool = new MockToolWithSymbol("mock-tool-with-symbol", toolHome.getAbsolutePath(), JenkinsRule.NO_PROPERTIES);
r.jenkins.getDescriptorByType(MockToolWithSymbol.MockToolWithSymbolDescriptor.class).setInstallations(misconfiguredTool, tool);

WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {def home = tool \"" + tool.getName() + "\"\n"
+"echo \"${home}\"}",
true));

r.assertLogContains(toolHome.getAbsolutePath(),
r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}

public static class MockToolWithSymbol extends ToolInstallation {
public MockToolWithSymbol(String name, String home, List<? extends ToolProperty<?>> properties) {
super(name, home, properties);
Expand Down

0 comments on commit 257ae6b

Please sign in to comment.