jenkinsci/jenkins-multijob-plugin

Restarted sub-job fails at multijob copy-artifacts step

Closed this issue · 1 comments

Jenkins ver. 2.176.1

ERROR: Build step failed with exception
java.lang.ClassCastException: hudson.model.Cause$UserIdCause cannot be cast to hudson.model.Cause$UpstreamCause
	at com.tikal.jenkins.plugins.multijob.MultiJobBuildSelector.getBuild(MultiJobBuildSelector.java:44)
	at hudson.plugins.copyartifact.CopyArtifact.perform(CopyArtifact.java:420)
	at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:79)
	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
	at hudson.model.Build$BuildExecution.build(Build.java:206)
	at hudson.model.Build$BuildExecution.doRun(Build.java:163)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
	at hudson.model.Run.execute(Run.java:1818)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:429)
Build step 'Copy artifacts from another project' marked build as failure

Probable fix:

diff --git a/src/main/java/com/tikal/jenkins/plugins/multijob/MultiJobBuildSelector.java b/src/main/java/com/tikal/jenkins/plugins/multijob/MultiJobBuildSelector.java
index 024959b..6e0d94e 100644
--- a/src/main/java/com/tikal/jenkins/plugins/multijob/MultiJobBuildSelector.java
+++ b/src/main/java/com/tikal/jenkins/plugins/multijob/MultiJobBuildSelector.java
@@ -41,6 +41,12 @@ public class MultiJobBuildSelector extends BuildSelector {
             // Matrix run is triggered by its parent project, so check causes of parent build:
             for (Cause cause : parent instanceof MatrixRun
                     ? ((MatrixRun)parent).getParentBuild().getCauses() : parent.getCauses()) {
+                if (cause instanceof UpstreamCause) {
+                    // We need only builds with upstream cause
+                } else {
+                    LOGGER.warning(String.format("'%s' Has no upstream build.", parent.getFullDisplayName()));
+                    break;
+                }
                 UpstreamCause upstreamCause = (UpstreamCause)cause;
                 Job upstreamJob = Jenkins.getInstance().getItemByFullName(upstreamCause.getUpstreamProject(), Job.class);
                 Run upstreamRun = upstreamJob.getBuildByNumber(upstreamCause.getUpstreamBuild());
@@ -48,6 +54,8 @@ public class MultiJobBuildSelector extends BuildSelector {
                 if (upstreamRun != null && upstreamRun instanceof MultiJobBuild) {
                     multiJobBuild = (MultiJobBuild)upstreamRun;
                 }
+                // We need only first cause, don't care about the previous
+                break;
             }
         }
         if (multiJobBuild == null) {