|
40 | 40 | import jenkins.branch.Branch;
|
41 | 41 | import jenkins.model.Jenkins;
|
42 | 42 | import jenkins.scm.api.SCMSourceOwner;
|
| 43 | +import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition; |
43 | 44 | import org.jenkinsci.plugins.workflow.flow.FlowDefinition;
|
44 | 45 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
|
45 | 46 | import org.jenkinsci.plugins.workflow.job.WorkflowRun;
|
@@ -245,31 +246,61 @@ private String defaultedVersionSCM(@NonNull Run<?, ?> run, @NonNull TaskListener
|
245 | 246 | }
|
246 | 247 | FlowDefinition fd = ((WorkflowJob)runParent).getDefinition();
|
247 | 248 | 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; |
250 | 251 | 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)"); |
254 | 257 | }
|
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; |
260 | 274 | }
|
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 { |
262 | 286 | 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"); |
266 | 290 | }
|
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 | + } |
273 | 304 | }
|
274 | 305 | }
|
275 | 306 | }
|
|
0 commit comments