From 922bccb63fe5ad4eb3973eb1747e3a8e30da866d Mon Sep 17 00:00:00 2001 From: Cyrille Le Clerc Date: Wed, 27 Mar 2019 23:51:22 +0100 Subject: [PATCH] [JENKINS-56228] port on the PipelineTriggerService the changes made on DownstreamPipelineTriggerRunListener --- .../maven/service/PipelineTriggerService.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/service/PipelineTriggerService.java b/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/service/PipelineTriggerService.java index c8a85cbd..e83cc8f2 100644 --- a/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/service/PipelineTriggerService.java +++ b/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/service/PipelineTriggerService.java @@ -1,6 +1,7 @@ package org.jenkinsci.plugins.pipeline.maven.service; import com.cloudbees.hudson.plugins.folder.computed.ComputedFolder; +import hudson.console.ModelHyperlinkNote; import hudson.model.Cause; import hudson.model.CauseAction; import hudson.model.Item; @@ -91,6 +92,7 @@ public Collection triggerDownstreamPipelines(@Nonnull Collection> jobsToTrigger = new TreeMap<>(); + Map> omittedPipelineTriggersByPipelineFullname = new HashMap<>(); // build the list of pipelines to trigger for(Map.Entry> entry: downstreamPipelinesByArtifact.entrySet()) { @@ -150,6 +152,7 @@ public Collection triggerDownstreamPipelines(@Nonnull Collection new TreeSet<>()).add(downstreamPipelineFullName); continue downstreamPipelinesLoop; } } @@ -189,7 +192,9 @@ public Collection triggerDownstreamPipelines(@Nonnull Collection triggeredPipelines = new ArrayList<>(); + // trigger the pipelines + triggerPipelinesLoop: for (Map.Entry> entry: jobsToTrigger.entrySet()) { String downstreamJobFullName = entry.getKey(); Job downstreamJob = Jenkins.getInstance().getItemByFullName(downstreamJobFullName, Job.class); @@ -198,13 +203,24 @@ public Collection triggerDownstreamPipelines(@Nonnull Collection(omittedPipelineTriggersByPipelineFullname.get(downstreamJobFullName))); // See jenkins.triggers.ReverseBuildTrigger.RunListenerImpl.onCompleted(Run, TaskListener) Run downstreamJobLastBuild = downstreamJob.getLastBuild(); if (downstreamJobLastBuild == null) { // should never happen, we need at least one build to know the dependencies } else { List matchingMavenDependencies = MavenDependencyCauseHelper.isSameCause(cause, downstreamJobLastBuild.getCauses()); - if (matchingMavenDependencies.size() > 0) { + if (matchingMavenDependencies.isEmpty()) { + for (Map.Entry> omittedPipeline : omittedPipelineTriggersByPipelineFullname.entrySet()) { + if (omittedPipeline.getValue().contains(downstreamJobFullName)) { + Job transitiveDownstreamJob = Jenkins.getInstance().getItemByFullName(entry.getKey(), Job.class); + logger.log(Level.INFO,"[withMaven] downstreamPipelineTriggerRunListener - Skip triggering " + + "downstream pipeline " + ModelHyperlinkNote.encodeTo(downstreamJob) + "because it will be triggered by transitive downstream " + transitiveDownstreamJob); + continue triggerPipelinesLoop; // don't trigger downstream pipeline + } + } + // trigger downstream pipeline + } else { downstreamJobLastBuild.addAction(new CauseAction((Cause) cause)); logger.log(Level.INFO, "Skip scheduling downstream pipeline " + logger.modelHyperlinkNoteEncodeTo(downstreamJob) + " as it was already triggered for Maven dependencies: " + matchingMavenDependencies.stream().map(mavenDependency -> mavenDependency == null ? null : mavenDependency.getShortDescription()).collect(Collectors.joining(", "))); @@ -213,9 +229,7 @@ public Collection triggerDownstreamPipelines(@Nonnull Collection