Skip to content
Permalink
Browse files

[JENKINS-46511] Option to only trigger downstream pipelines when the …

…generated artifact has been "mvn deploy", not "mvn package" or "mvn install"
  • Loading branch information...
cyrille-leclerc committed Aug 28, 2017
1 parent 92d6a33 commit e431bd8a85a96f535aa00bd1ed95bbd65099737a
@@ -18,6 +18,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;
@@ -49,6 +50,12 @@

private boolean skipDownstreamTriggers;

/**
* Skip trigger of downstream pipelines if the artifact has just been
* packaged (mvn package) or installed locally (mvn install)
*/
private boolean skipDownstreamTriggersForNonDeployedArtifacts;

private boolean ignoreUpstreamTriggers;

@DataBoundConstructor
@@ -82,7 +89,10 @@ public void process(@Nonnull StepContext context, @Nonnull Element mavenSpyLogsE

protected void recordDependencies(@Nonnull Element mavenSpyLogsElt, @Nonnull Run run, @Nonnull TaskListener listener, @Nonnull PipelineMavenPluginDao dao) {
List<MavenSpyLogProcessor.MavenDependency> dependencies = listDependencies(mavenSpyLogsElt);
recordDependencies(dependencies, run, listener, dao);
}

protected void recordDependencies(List<MavenSpyLogProcessor.MavenDependency> dependencies, @Nonnull Run run, @Nonnull TaskListener listener, @Nonnull PipelineMavenPluginDao dao) {
if (LOGGER.isLoggable(Level.FINE)) {
listener.getLogger().println("[withMaven] pipelineGraphPublisher - recordDependencies - filter: " +
"versions[snapshot: " + isIncludeSnapshotVersions() + ", release: " + isIncludeReleaseVersions() + "], " +
@@ -130,10 +140,14 @@ protected void recordDependencies(@Nonnull Element mavenSpyLogsElt, @Nonnull Run
}

protected void recordGeneratedArtifacts(@Nonnull Element mavenSpyLogsElt, @Nonnull Run run, @Nonnull TaskListener listener, @Nonnull PipelineMavenPluginDao dao) {
List<MavenSpyLogProcessor.MavenArtifact> generatedArtifacts = listArtifacts(mavenSpyLogsElt);
recordGeneratedArtifacts(generatedArtifacts, run, listener, dao);
}

protected void recordGeneratedArtifacts(List<MavenSpyLogProcessor.MavenArtifact> generatedArtifacts, @Nonnull Run run, @Nonnull TaskListener listener, @Nonnull PipelineMavenPluginDao dao) {
if (LOGGER.isLoggable(Level.FINE)) {
listener.getLogger().println("[withMaven] pipelineGraphPublisher - recordGeneratedArtifacts...");
}
List<MavenSpyLogProcessor.MavenArtifact> generatedArtifacts = listArtifacts(mavenSpyLogsElt);
for(MavenSpyLogProcessor.MavenArtifact artifact: generatedArtifacts) {

if (LOGGER.isLoggable(Level.FINE)) {
@@ -142,9 +156,11 @@ protected void recordGeneratedArtifacts(@Nonnull Element mavenSpyLogsElt, @Nonnu
listener.getLogger().println("[withMaven] pipelineGraphPublisher - Record generated artifact: " + artifact.getId() + ", version: " + artifact.version + ", skipDownstreamTriggers: " + skipDownstreamTriggers +
", file: " + artifact.file);
}
boolean skipDownstreamPipelines = this.skipDownstreamTriggers ||
(this.skipDownstreamTriggersForNonDeployedArtifacts && !Objects.equals(artifact.baseVersion, artifact.version));
dao.recordGeneratedArtifact(run.getParent().getFullName(), run.getNumber(),
artifact.groupId, artifact.artifactId, artifact.version, artifact.type, artifact.baseVersion,
this.skipDownstreamTriggers);
skipDownstreamPipelines);
}
}

@@ -315,6 +331,15 @@ public void setIgnoreUpstreamTriggers(boolean ignoreUpstreamTriggers) {
this.ignoreUpstreamTriggers = ignoreUpstreamTriggers;
}

public boolean isSkipDownstreamTriggersForNonDeployedArtifacts() {
return skipDownstreamTriggersForNonDeployedArtifacts;
}

@DataBoundSetter
public void setSkipDownstreamTriggersForNonDeployedArtifacts(boolean skipDownstreamTriggersForNonDeployedArtifacts) {
this.skipDownstreamTriggersForNonDeployedArtifacts = skipDownstreamTriggersForNonDeployedArtifacts;
}

@Symbol("pipelineGraphPublisher")
@Extension
public static class DescriptorImpl extends MavenPublisher.DescriptorImpl {

0 comments on commit e431bd8

Please sign in to comment.
You can’t perform that action at this time.