Skip to content

Commit

Permalink
STOPPED stage in a branch should not fail the pipeline if all requisi…
Browse files Browse the repository at this point in the history
…te stages succeeded

- Replaced explicitly exception throw with a STOPPED return result
  • Loading branch information
jeyrschabu committed Oct 25, 2016
1 parent fdf052c commit 0bf72e8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ class WaitForRequisiteCompletionTask implements RetryableTask {
}

// we don't want to fail this join point on a STOPPED upstream until all upstreams are in a completed state.
// STOPPED shouldn't fail execution of the pipeline, but is not a legitimate join state
// STOPPED shouldn't fail execution of the pipeline
if (allRequisiteStagesAreComplete && stoppedStageNames) {
throw new IllegalStateException("Requisite stages were stopped: ${stoppedStageNames.join(',')}")
return new DefaultTaskResult(STOPPED)
}

return new DefaultTaskResult(allRequisiteStagesAreComplete ? SUCCEEDED : RUNNING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,43 +101,55 @@ class WaitForRequisiteCompletionTaskSpec extends Specification {
TERMINAL | TERMINAL || ["parent", "synthetic"]
}

def "should fail with an exception if all requisite stages completed but any were STOPPED"() {
def "should continue running if a requisite stage is STOPPED but not all stages are complete"() {
given:
def pipeline = new Pipeline()
pipeline.stages << new PipelineStage(pipeline, "test", "parentA", ["refId": "1"])
pipeline.stages << new PipelineStage(pipeline, "test", "parentB", ["refId": "2"])

pipeline.stages[0].status = parentAStatus
pipeline.stages[1].status = parentBStatus
pipeline.stages[1].parentStageId = pipeline.stages[0].id
pipeline.stages[0].status = STOPPED
pipeline.stages[1].status = RUNNING
pipeline.stages[1].parentStageId = pipeline.stages[0].id

when:
task.execute(new PipelineStage(pipeline, null, [requisiteIds: ["1", "2"]]))
def result = task.execute(new PipelineStage(pipeline, null, [requisiteIds: ["1", "2"]]))

then:
def ex = thrown(IllegalStateException)
ex.message == "Requisite ${failureCondition}: ${expectedStageNames.join(",")}".toString()

where:
parentAStatus | parentBStatus | expectedStageNames | failureCondition
STOPPED | SUCCEEDED | ["parentA"] | "stages were stopped"
TERMINAL | STOPPED | ["parentA"] | "stage failures"
result.status == RUNNING
}

def "should continue running if a requisite stage is STOPPED but not all stages are complete"() {
def "should stop running if a requisite stage is STOPPED all stages are complete"() {
given:
def pipeline = new Pipeline()
pipeline.stages << new PipelineStage(pipeline, "test", "parentA", ["refId": "1"])
pipeline.stages << new PipelineStage(pipeline, "test", "parentB", ["refId": "2"])

pipeline.stages[0].status = STOPPED
pipeline.stages[1].status = RUNNING
pipeline.stages[1].status = SUCCEEDED
pipeline.stages[1].parentStageId = pipeline.stages[0].id

when:
def result = task.execute(new PipelineStage(pipeline, null, [requisiteIds: ["1", "2"]]))

then:
result.status == RUNNING
result.status == STOPPED
notThrown(IllegalStateException)
}

def "should fail if a requisite stage is STOPPED but any failed"() {
given:
def pipeline = new Pipeline()
pipeline.stages << new PipelineStage(pipeline, "test", "parentA", ["refId": "1"])
pipeline.stages << new PipelineStage(pipeline, "test", "parentB", ["refId": "2"])

pipeline.stages[0].status = STOPPED
pipeline.stages[1].status = TERMINAL
pipeline.stages[1].parentStageId = pipeline.stages[0].id

when:
task.execute(new PipelineStage(pipeline, null, [requisiteIds: ["1", "2"]]))

then:
thrown(IllegalStateException)
}
}

0 comments on commit 0bf72e8

Please sign in to comment.