Skip to content

Commit b8c35fb

Browse files
committed
SCMSourceRetrieverTest: rename checkDefaultVersion() to checkDefaultVersionStaticStrings() and limit influence of caller-defined BRANCH_NAME [JENKINS-69731]
1 parent ba5e325 commit b8c35fb

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/test/java/org/jenkinsci/plugins/workflow/libs/SCMSourceRetrieverTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public class SCMSourceRetrieverTest {
219219
}
220220

221221
@Issue("JENKINS-69731")
222-
@Test public void checkDefaultVersion() throws Exception {
222+
@Test public void checkDefaultVersionStaticStrings() throws Exception {
223223
sampleRepo.init();
224224
sampleRepo.write("vars/myecho.groovy", "def call() {echo 'something special'}");
225225
sampleRepo.git("add", "vars");
@@ -253,11 +253,14 @@ public class SCMSourceRetrieverTest {
253253
WorkflowRun b2 = r.buildAndAssertSuccess(p2);
254254
r.assertLogContains("something very special", b2);
255255

256-
// Branch context for job not set - fall back to default
257-
WorkflowJob p3 = r.jenkins.createProject(WorkflowJob.class, "p3");
258-
p3.setDefinition(new CpsFlowDefinition("@Library('branchylib@${BRANCH_NAME}') import myecho; myecho()", true));
259-
WorkflowRun b3 = r.buildAndAssertSuccess(p3);
260-
r.assertLogContains("something special", b3);
256+
// Do not let caller-provided BRANCH_NAME interfere here
257+
if (System.getenv("BRANCH_NAME") == null) {
258+
// Branch context for job not set - fall back to default
259+
WorkflowJob p3 = r.jenkins.createProject(WorkflowJob.class, "p3");
260+
p3.setDefinition(new CpsFlowDefinition("@Library('branchylib@${BRANCH_NAME}') import myecho; myecho()", true));
261+
WorkflowRun b3 = r.buildAndAssertSuccess(p3);
262+
r.assertLogContains("something special", b3);
263+
}
261264

262265
// Use a specified but missing branch
263266
WorkflowJob p4 = r.jenkins.createProject(WorkflowJob.class, "p4");

0 commit comments

Comments
 (0)