|
37 | 37 | import hudson.model.TaskListener;
|
38 | 38 | import hudson.scm.SCM;
|
39 | 39 | import hudson.util.FormValidation;
|
| 40 | +import jenkins.branch.Branch; |
40 | 41 | import jenkins.model.Jenkins;
|
| 42 | +import jenkins.scm.api.SCMSourceOwner; |
41 | 43 | import org.jenkinsci.plugins.workflow.flow.FlowDefinition;
|
42 | 44 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
|
43 | 45 | import org.jenkinsci.plugins.workflow.job.WorkflowRun;
|
@@ -274,34 +276,41 @@ private String defaultedVersionSCM(@NonNull Run<?, ?> run, @NonNull TaskListener
|
274 | 276 | }
|
275 | 277 |
|
276 | 278 | if (scm0 == null) {
|
277 |
| - Collection<SCM> wjscms = (Collection<SCM>) ((WorkflowJob)runParent).getSCMs();; |
278 |
| - if (wjscms.isEmpty()) { |
| 279 | + // WARNING: the WorkflowJob.getSCMs() does not return SCMs |
| 280 | + // associated with the current build configuration, but |
| 281 | + // rather those that were associated with previous runs |
| 282 | + // for different branches (with lastSuccessfulBuild on top)! |
| 283 | + BranchJobProperty property = ((WorkflowJob)runParent).getProperty(BranchJobProperty.class); |
| 284 | + if (property == null) { // && !(runParent.getParent() instanceof SCMSourceOwner)) { |
279 | 285 | if (logger != null) {
|
280 | 286 | logger.println("defaultedVersion(): " +
|
281 | 287 | "WorkflowJob '" +
|
282 | 288 | runParent.getClass().getName() +
|
283 | 289 | "' is not associated with any SCMs");
|
284 | 290 | }
|
285 | 291 | } else {
|
| 292 | + Branch pipelineBranch = property.getBranch(); |
286 | 293 | if (logger != null) {
|
287 | 294 | logger.println("defaultedVersion(): " +
|
288 | 295 | "inspecting WorkflowJob '" +
|
289 | 296 | runParent.getClass().getName() +
|
290 | 297 | "' for SCMs it might use");
|
291 | 298 | }
|
292 |
| - for (SCM scmN : wjscms) { |
| 299 | + if (pipelineBranch != null) { |
293 | 300 | if (logger != null) {
|
294 |
| - logger.println("defaultedVersion(): inspecting SCM '" + |
295 |
| - scmN.getClass().getName() + |
296 |
| - "': " + scmN.toString()); |
| 301 | + logger.println("defaultedVersion(): inspecting pipelineBranch '" + |
| 302 | + pipelineBranch.getClass().getName() + |
| 303 | + "': " + pipelineBranch.toString()); |
297 | 304 | }
|
298 |
| - if ("hudson.plugins.git.GitSCM".equals(scmN.getClass().getName())) { |
| 305 | +/* |
| 306 | + if ("hudson.plugins.git.GitSCM".equals(scmN.getClass().getName())) { |
299 | 307 | // The best we can do here is accept
|
300 | 308 | // the first seen SCM (with branch
|
301 | 309 | // support which we know how to query).
|
302 | 310 | scm0 = scmN;
|
303 | 311 | break;
|
304 | 312 | }
|
| 313 | +*/ |
305 | 314 | }
|
306 | 315 | }
|
307 | 316 | }
|
|
0 commit comments