Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMHeadObserver;
Expand Down Expand Up @@ -90,6 +91,10 @@ public class ResolveScmStep extends Step {
@DataBoundConstructor
public ResolveScmStep(@NonNull SCMSource source, @NonNull List<String> targets) {
this.source = source;
// JENKINS-67005: Pipeline passes null when targets is omitted from the step call.
Objects.requireNonNull(
targets,
"targets is required; provide candidate branch names, e.g. targets: [env.BRANCH_NAME, 'main']");
this.targets = new ArrayList<>(targets);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package org.jenkinsci.plugins.workflow.multibranch;

import hudson.model.TopLevelItem;
import java.util.Collections;
import jenkins.scm.impl.mock.MockSCMController;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
Expand All @@ -34,6 +35,10 @@
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.fail;

public class ResolveScmStepTest {

@ClassRule
Expand Down Expand Up @@ -121,4 +126,16 @@ public void given_nonExistingHeadName_when_invokedWithDefault_then_defaultReturn
j.buildAndAssertSuccess(job);
}
}

@Test
Comment thread
Chikzz2001 marked this conversation as resolved.
public void constructorRejectsNullTargetsWithClearMessage() {
try {
new ResolveScmStep(null, null);
fail("expected NullPointerException");
} catch (NullPointerException e) {
assertThat(e.getMessage(), containsString("targets is required"));
}
new ResolveScmStep(null, Collections.emptyList());
}

}
Loading