Skip to content

Commit

Permalink
fix(dependent pipelines): failure to trigger a dependend pipeline sho…
Browse files Browse the repository at this point in the history
…uldn't affect others (#3258)

* fix(dependent pipelines): failure to trigger a dependend pipeline shouldn't affect others

Failure in planning a, say, a single v2 templated pipeline will cause no dependent pipelines to start.
This is due to exception not being localized to each individual pipeline

* fixup! fix(dependent pipelines): failure to trigger a dependend pipeline shouldn't affect others
  • Loading branch information
marchello2000 authored and mergify[bot] committed Oct 25, 2019
1 parent b6faf6f commit 7f02cb8
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,37 +74,50 @@ class DependentPipelineExecutionListener implements ExecutionListener {
// Resolve templated pipelines if enabled.
allPipelines = allPipelines.collect { pipeline ->
if (V2Util.isV2Pipeline(pipeline)) {
return V2Util.planPipeline(contextParameterProcessor, executionPreprocessors, pipeline)
try {
return V2Util.planPipeline(contextParameterProcessor, executionPreprocessors, pipeline)
} catch (Exception e) {
log.error("Failed to plan V2 templated pipeline {}", pipeline.getOrDefault("id", "<UNKNOWN ID>"), e)
return null
}
} else {
return pipeline
}
}
}

allPipelines.findAll { !it.disabled }
allPipelines.findAll { (it != null) && (!it.disabled) }
.each {
it.triggers.each { trigger ->
if (trigger.enabled &&
trigger.type == 'pipeline' &&
trigger.pipeline &&
trigger.pipeline == execution.pipelineConfigId &&
trigger.status.contains(status)
) {
User authenticatedUser = null
try {
if (trigger.enabled &&
trigger.type == 'pipeline' &&
trigger.pipeline &&
trigger.pipeline == execution.pipelineConfigId &&
trigger.status.contains(status)
) {
User authenticatedUser = null

if (fiatStatus.enabled && trigger.runAsUser) {
authenticatedUser = new User()
authenticatedUser.setEmail(trigger.runAsUser)
}
if (fiatStatus.enabled && trigger.runAsUser) {
authenticatedUser = new User()
authenticatedUser.setEmail(trigger.runAsUser)
}

dependentPipelineStarter.trigger(
it,
execution.trigger?.user as String,
execution,
[:],
null,
authenticatedUser
)
dependentPipelineStarter.trigger(
it,
execution.trigger?.user as String,
execution,
[:],
null,
authenticatedUser
)
}
}
catch (Exception e) {
log.error(
"Failed to process triggers for pipeline {} while triggering dependent pipelines",
it.getOrDefault("id", "<UNKNOWN ID>"),
e)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,37 @@ class DependentPipelineExecutionListenerSpec extends Specification {
status << [ExecutionStatus.SUCCEEDED, ExecutionStatus.TERMINAL]
}

def "should trigger downstream v2 templated pipeline even when templates are invalid"() {
given:
pipeline.stages.each {
it.status = ExecutionStatus.SUCCEEDED
it.tasks = [Mock(Task)]
}

pipeline.pipelineConfigId = "97c435a0-0faf-11e5-a62b-696d38c37faa"
front50Service.getAllPipelines() >> [
v2MptPipelineConfig, v2MptPipelineConfig
]
GroovyMock(V2Util, global: true)
V2Util.planPipeline(_, _, v2MptPipelineConfig) >>
{throw new Exception("planning failed")} >>
v2MptPipelineConfig
V2Util.isV2Pipeline(_) >> true

when:
listener.afterExecution(null, pipeline, null, true)

then:
1 * dependentPipelineStarter.trigger(_, _, _, _, _, _)
}

def "should not trigger downstream pipeline when conditions don't match"() {
given:
pipeline.stages.each {
it.status = status
it.tasks = [Mock(Task)]
}


pipeline.pipelineConfigId = id

pipelineConfig.triggers.first().status = ['successful']
Expand Down

0 comments on commit 7f02cb8

Please sign in to comment.