Skip to content

Commit 2d098a5

Browse files
committed
LibraryConfiguration.java: defaultedVersionSCM(): check for nuances of CpsScmFlowDefinition [JENKINS-69731]
1 parent 6ab574a commit 2d098a5

File tree

1 file changed

+51
-20
lines changed

1 file changed

+51
-20
lines changed

src/main/java/org/jenkinsci/plugins/workflow/libs/LibraryConfiguration.java

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import jenkins.branch.Branch;
4141
import jenkins.model.Jenkins;
4242
import jenkins.scm.api.SCMSourceOwner;
43+
import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition;
4344
import org.jenkinsci.plugins.workflow.flow.FlowDefinition;
4445
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
4546
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
@@ -245,31 +246,61 @@ private String defaultedVersionSCM(@NonNull Run<?, ?> run, @NonNull TaskListener
245246
}
246247
FlowDefinition fd = ((WorkflowJob)runParent).getDefinition();
247248
if (fd != null) {
248-
Collection<SCM> fdscms = (Collection<SCM>) fd.getSCMs();
249-
if (fdscms.isEmpty()) {
249+
if (fd instanceof CpsScmFlowDefinition) {
250+
CpsScmFlowDefinition csfd = (CpsScmFlowDefinition)fd;
250251
if (logger != null) {
251-
logger.println("defaultedVersion(): FlowDefinition '" +
252-
fd.getClass().getName() +
253-
"' is not associated with any SCMs");
252+
logger.println("defaultedVersion(): inspecting CpsScmFlowDefinition '" +
253+
csfd.getClass().getName() +
254+
"' for an SCM it might use (with" +
255+
(csfd.isLightweight() ? "" : "out") +
256+
" lightweight checkout)");
254257
}
255-
} else {
256-
if (logger != null) {
257-
logger.println("defaultedVersion(): inspecting FlowDefinition '" +
258-
fd.getClass().getName() +
259-
"' for SCMs it might use");
258+
scm0 = csfd.getScm();
259+
260+
if (scm0 == null) {
261+
if (logger != null) {
262+
logger.println("defaultedVersion(): CpsScmFlowDefinition '" +
263+
csfd.getClass().getName() +
264+
"' is not associated with an SCM");
265+
}
266+
} else if (!("hudson.plugins.git.GitSCM".equals(scm0.getClass().getName()))) {
267+
if (logger != null) {
268+
logger.println("defaultedVersion(): CpsScmFlowDefinition '" +
269+
csfd.getClass().getName() +
270+
"' is associated with an SCM we can not query: " +
271+
scm0.toString());
272+
}
273+
scm0 = null;
260274
}
261-
for (SCM scmN : fdscms) {
275+
}
276+
277+
if (scm0 == null) {
278+
Collection<SCM> fdscms = (Collection<SCM>) fd.getSCMs();
279+
if (fdscms.isEmpty()) {
280+
if (logger != null) {
281+
logger.println("defaultedVersion(): generic FlowDefinition '" +
282+
fd.getClass().getName() +
283+
"' is not associated with any SCMs");
284+
}
285+
} else {
262286
if (logger != null) {
263-
logger.println("defaultedVersion(): inspecting SCM '" +
264-
scmN.getClass().getName() +
265-
"': " + scmN.toString());
287+
logger.println("defaultedVersion(): inspecting generic FlowDefinition '" +
288+
fd.getClass().getName() +
289+
"' for SCMs it might use");
266290
}
267-
if ("hudson.plugins.git.GitSCM".equals(scmN.getClass().getName())) {
268-
// The best we can do here is accept
269-
// the first seen SCM (with branch
270-
// support which we know how to query).
271-
scm0 = scmN;
272-
break;
291+
for (SCM scmN : fdscms) {
292+
if (logger != null) {
293+
logger.println("defaultedVersion(): inspecting SCM '" +
294+
scmN.getClass().getName() +
295+
"': " + scmN.toString());
296+
}
297+
if ("hudson.plugins.git.GitSCM".equals(scmN.getClass().getName())) {
298+
// The best we can do here is accept
299+
// the first seen SCM (with branch
300+
// support which we know how to query).
301+
scm0 = scmN;
302+
break;
303+
}
273304
}
274305
}
275306
}

0 commit comments

Comments
 (0)