-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skipping when Guard evaluates as False -- ContinueAfterSkip
When a `Condition` fails, the guarded `Task` and its branch (dependent `Tasks`) are skipped. A `Task` is dependent on and in the branch of another `Task` as specified by ordering using `runAfter` or by resources using `Results`, `Workspaces` and `Resources`. In some use cases of `Conditions`, when a `Condition` evaluates to `False`, users need to skip the guarded `Task` only and allow dependent `Tasks` to execute. An example use case is when there’s a particular `Task` that a Pipeline wants to execute when the git branch is dev/staging/qa, but not when it’s the main/master/prod branch. Another use case is when a user wants to send out a notification whether or not a parent guarded `Task` was executed, as described in [this issue](#2937). In this PR, we add a `continueAfterSkip` field to specify whether to terminate the whole `Task` branch, or to skip the guarded `Task` only and continue with the rest of the `Task` branch. When a `Condition` evaluates to `False`, to skip the guarded `Task` only and allow dependent `Tasks` to execute, users can pass in the `continueAfterSkip` field and set it to `true` or `yes` (case insensitive). The field defaults to `false` -- the rest of the `Task` branch is skipped by default as it was previously. When `continueAfterSkip` is set to `True`, subsequent `Tasks` based on ordering dependencies should execute and the subsequent `Tasks` based resource dependencies will have resource validation errors.
- Loading branch information
Showing
11 changed files
with
424 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
examples/v1alpha1/pipelineruns/conditional-pipelinerun-continue-after-skip-ordering.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Condition | ||
metadata: | ||
name: always-false | ||
spec: | ||
check: | ||
image: alpine | ||
script: | | ||
exit 1 | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Task | ||
metadata: | ||
name: echo-expected | ||
spec: | ||
steps: | ||
- name: echo-expected | ||
image: ubuntu | ||
script: 'echo expected' | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Task | ||
metadata: | ||
name: echo-unexpected | ||
spec: | ||
steps: | ||
- name: echo-file-exists | ||
image: ubuntu | ||
script: 'echo UNEXPECTED!' | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Pipeline | ||
metadata: | ||
name: conditional-pipeline | ||
spec: | ||
tasks: | ||
- name: task-should-be-skipped # failed | ||
conditions: | ||
- conditionRef: always-false | ||
continueAfterSkip: 'true' # allows executing dependent tasks | ||
taskRef: | ||
name: echo-unexpected | ||
- name: task-should-execute # succeeded | ||
taskRef: | ||
name: echo-expected | ||
runAfter: | ||
- task-should-be-skipped | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: PipelineRun | ||
metadata: | ||
name: conditional-pr-continue-after-skip-ordering | ||
spec: | ||
pipelineRef: | ||
name: conditional-pipeline | ||
serviceAccountName: 'default' |
134 changes: 134 additions & 0 deletions
134
examples/v1alpha1/pipelineruns/conditional-pipelinerun-continue-after-skip-resource.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Condition | ||
metadata: | ||
name: is-equal | ||
spec: | ||
params: | ||
- name: left | ||
type: string | ||
- name: right | ||
type: string | ||
check: | ||
image: alpine | ||
script: | | ||
#!/bin/sh | ||
if [ $(params.left) = $(params.right) ]; then | ||
echo "$(params.left) == $(params.right)" | ||
exit 0 | ||
else | ||
echo "$(params.left) != $(params.right)" | ||
exit 1 | ||
fi | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Task | ||
metadata: | ||
name: sum | ||
annotations: | ||
description: | | ||
A simple task that sums the two provided integers | ||
spec: | ||
inputs: | ||
params: | ||
- name: a | ||
type: string | ||
default: "1" | ||
description: The first integer | ||
- name: b | ||
type: string | ||
default: "1" | ||
description: The second integer | ||
results: | ||
- name: sum | ||
description: The sum of the two provided integers | ||
steps: | ||
- name: sum | ||
image: bash:latest | ||
script: | | ||
#!/usr/bin/env bash | ||
echo -n $(( "$(inputs.params.a)" + "$(inputs.params.b)" )) | tee $(results.sum.path) | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Task | ||
metadata: | ||
name: multiply | ||
annotations: | ||
description: | | ||
A simple task that multiplies the two provided integers | ||
spec: | ||
inputs: | ||
params: | ||
- name: a | ||
type: string | ||
default: "1" | ||
description: The first integer | ||
- name: b | ||
type: string | ||
default: "1" | ||
description: The second integer | ||
results: | ||
- name: product | ||
description: The product of the two provided integers | ||
steps: | ||
- name: product | ||
image: bash:latest | ||
script: | | ||
#!/usr/bin/env bash | ||
echo -n $(( "$(inputs.params.a)" * "$(inputs.params.b)" )) | tee $(results.product.path) | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Pipeline | ||
metadata: | ||
name: condition-pipeline | ||
spec: | ||
params: | ||
- name: a | ||
type: string | ||
- name: b | ||
type: string | ||
tasks: | ||
- name: sum-inputs # condition evaluates to false, should be skipped (failed) | ||
conditions: | ||
- conditionRef: is-equal | ||
params: | ||
- name: left | ||
value: "1" | ||
- name: right | ||
value: $(params.b) | ||
continueAfterSkip: 'true' | ||
taskRef: | ||
name: sum | ||
params: | ||
- name: a | ||
value: "$(params.a)" | ||
- name: b | ||
value: "$(params.b)" | ||
- name: multiply-inputs # should execute (succeeded) | ||
taskRef: | ||
name: multiply | ||
params: | ||
- name: a | ||
value: "$(params.a)" | ||
- name: b | ||
value: "$(params.b)" | ||
- name: sum-and-multiply # should execute, resolution error (failed) | ||
taskRef: | ||
name: sum | ||
params: | ||
- name: a | ||
value: "$(tasks.multiply-inputs.results.product)$(tasks.sum-inputs.results.sum)" | ||
- name: b | ||
value: "$(tasks.multiply-inputs.results.product)$(tasks.sum-inputs.results.sum)" | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: PipelineRun | ||
metadata: | ||
name: condition-pipelinerun-resources | ||
spec: | ||
params: | ||
- name: a | ||
value: "1" | ||
- name: b | ||
value: "2" | ||
pipelineRef: | ||
name: condition-pipeline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.