@@ -1079,6 +1079,46 @@ private void sampleRepo2ContentUniqueMasterFeatureBogus_staticStrings(String sub
10791079 }
10801080 }
10811081
1082+ @ Issue ("JENKINS-69731" )
1083+ @ Test public void checkDefaultVersion_singleBranch_BRANCH_NAME_lightweight () throws Exception {
1084+ // Test that lightweight checkouts from SCM allow
1085+ // @Library('branchylib@${BRANCH_NAME}') to see
1086+ // sufficient SCM context to determine the branch.
1087+ assumeFalse ("An externally provided BRANCH_NAME envvar interferes with tested logic" ,
1088+ System .getenv ("BRANCH_NAME" ) != null );
1089+
1090+ sampleRepo1ContentMasterFeature ();
1091+ SCMSourceRetriever scm = new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true ));
1092+ LibraryConfiguration lc = new LibraryConfiguration ("branchylib" , scm );
1093+ lc .setDefaultVersion ("master" );
1094+ lc .setIncludeInChangesets (false );
1095+ lc .setAllowVersionOverride (false );
1096+ lc .setAllowBRANCH_NAME (true );
1097+ lc .setTraceDefaultedVersion (true );
1098+ GlobalLibraries .get ().setLibraries (Collections .singletonList (lc ));
1099+
1100+ // Inspired in part by tests like
1101+ // https://github.com/jenkinsci/workflow-multibranch-plugin/blob/master/src/test/java/org/jenkinsci/plugins/workflow/multibranch/NoTriggerBranchPropertyWorkflowTest.java#L132
1102+ sampleRepo2ContentSameMasterFeatureBogus_BRANCH_NAME ();
1103+
1104+ // Get a non-default branch loaded for this single-branch build:
1105+ GitSCM gitSCM = new GitSCM (
1106+ GitSCM .createRepoList (sampleRepo2 .toString (), null ),
1107+ Collections .singletonList (new BranchSpec ("*/feature" )),
1108+ null , null , Collections .emptyList ());
1109+
1110+ CpsScmFlowDefinition csfd = new CpsScmFlowDefinition (gitSCM , "Jenkinsfile" );
1111+ csfd .setLightweight (true );
1112+ WorkflowJob p0 = r .jenkins .createProject (WorkflowJob .class , "p0" );
1113+ p0 .setDefinition (csfd );
1114+ sampleRepo2 .notifyCommit (r );
1115+ r .waitUntilNoActivity ();
1116+
1117+ WorkflowRun b0 = r .buildAndAssertSuccess (p0 );
1118+ r .assertLogContains ("Loading library branchylib@feature" , b0 );
1119+ r .assertLogContains ("something very special" , b0 );
1120+ }
1121+
10821122 @ Issue ("JENKINS-69731" )
10831123 @ Test public void checkDefaultVersion_inline_allowVersionEnvvar () throws Exception {
10841124 // Test that @Library('branchylib@${env.TEST_VAR_NAME}')
0 commit comments