-
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.
Task inputs and outputs are considered required, there is no way today to mark them optional. This change introduce a new field called optional as part of the PipelineResourceDeclaration by default a resource is required. To mark any resource optional, set optional to true: apiVersion: tekton.dev/v1alpha1 kind: Task metadata: name: task-check-workspace spec: inputs: resources: - name: workspace type: git optional: true steps: - name: check-workspace
- Loading branch information
1 parent
5830188
commit ccacb0c
Showing
15 changed files
with
604 additions
and
27 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
88 changes: 88 additions & 0 deletions
88
examples/pipelineruns/conditional-pipelinerun-with-optional-resources.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,88 @@ | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Condition | ||
metadata: | ||
name: verify-no-file-exists-without-resource | ||
spec: | ||
params: | ||
- name: "path" | ||
resources: | ||
- name: optional-workspace | ||
type: git | ||
optional: true | ||
check: | ||
image: alpine | ||
command: ["/bin/sh"] | ||
args: ['-c', 'test ! -f $(resources.optional-workspace.path)/$(params.path)'] | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: PipelineResource | ||
metadata: | ||
name: pipeline-git-repo | ||
spec: | ||
type: git | ||
params: | ||
- name: revision | ||
value: master | ||
- name: url | ||
value: https://github.com/tektoncd/pipeline | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Task | ||
metadata: | ||
name: list-pipeline-repo-files | ||
spec: | ||
inputs: | ||
resources: | ||
- name: optional-workspace | ||
type: git | ||
optional: true | ||
steps: | ||
- name: run-ls | ||
image: ubuntu | ||
script: | | ||
#!/usr/bin/env bash | ||
ls -al $(inputs.resources.optional-workspace.path) | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Pipeline | ||
metadata: | ||
name: pipeline-list-pipeline-repo-files | ||
spec: | ||
resources: | ||
- name: pipeline-source-repo | ||
type: git | ||
params: | ||
- name: "path" | ||
default: "README.md" | ||
tasks: | ||
- name: list-pipeline-repo-files-1 | ||
taskRef: | ||
name: list-pipeline-repo-files | ||
conditions: | ||
- conditionRef: "verify-no-file-exists-without-resource" | ||
params: | ||
- name: "path" | ||
value: "$(params.path)" | ||
# NOTE: Resource "optional-workspace" is declared as optional in Condition | ||
# No resource specified for the condition here since its optional | ||
# "DO NOT UNCOMMENT THE FOLLOWING RESOURCE" | ||
# resources: | ||
# - name: optional-workspace | ||
# resource: pipeline-source-repo | ||
resources: | ||
inputs: | ||
- name: optional-workspace | ||
resource: pipeline-source-repo | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: PipelineRun | ||
metadata: | ||
name: demo-condtional-pr-without-condition-resource | ||
spec: | ||
pipelineRef: | ||
name: pipeline-list-pipeline-repo-files | ||
serviceAccountName: 'default' | ||
resources: | ||
- name: pipeline-source-repo | ||
resourceRef: | ||
name: pipeline-git-repo |
35 changes: 35 additions & 0 deletions
35
examples/taskruns/optional-resources-with-clustertask.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,35 @@ | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: ClusterTask | ||
metadata: | ||
name: clustertask-with-optional-resources | ||
spec: | ||
inputs: | ||
resources: | ||
- name: git-repo | ||
type: git | ||
optional: true | ||
params: | ||
- name: filename | ||
type: string | ||
default: "README.md" | ||
outputs: | ||
resources: | ||
- name: optionalimage | ||
type: image | ||
optional: true | ||
steps: | ||
- name: task-echo-success | ||
image: ubuntu | ||
script: | | ||
#!/usr/bin/env bash | ||
echo "success" | ||
--- | ||
|
||
apiVersion: tekton.dev/v1alpha1 | ||
kind: TaskRun | ||
metadata: | ||
name: clustertask-without-resources | ||
spec: | ||
taskRef: | ||
name: clustertask-with-optional-resources | ||
kind: ClusterTask |
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,131 @@ | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Task | ||
metadata: | ||
name: task-check-optional-resources | ||
spec: | ||
inputs: | ||
resources: | ||
- name: git-repo | ||
type: git | ||
optional: true | ||
params: | ||
- name: filename | ||
type: string | ||
default: "README.md" | ||
outputs: | ||
resources: | ||
- name: optionalimage | ||
type: image | ||
optional: true | ||
steps: | ||
- name: check-git-repo | ||
image: ubuntu | ||
script: | | ||
#!/usr/bin/env bash | ||
if [ -d $(inputs.resources.git-repo.path) ]; then | ||
echo "Git repo was cloned at $(inputs.resources.git-repo.path)" | ||
if [ -f $(inputs.resources.git-repo.path)/$(inputs.params.filename) ]; then | ||
echo "$(inputs.params.filename) does exist at $(inputs.resources.git-repo.path)" | ||
else | ||
echo "$(inputs.params.filename) does not exist at $(inputs.resources.git-repo.path)" | ||
fi | ||
else | ||
echo "Git repo was not cloned at $(inputs.resources.git-repo.path)" | ||
fi | ||
if [ "$(outputs.resources.optionalimage.url)" == "" ]; then | ||
echo "Image URL: $(outputs.resources.optionalimage.url)" | ||
else | ||
echo "No image URL specified." | ||
fi | ||
echo "Yay, Input and Output Resources can be Optional!" | ||
--- | ||
|
||
apiVersion: tekton.dev/v1alpha1 | ||
kind: TaskRun | ||
metadata: | ||
name: demo-optional-inputs-resources-with-resources | ||
spec: | ||
inputs: | ||
resources: | ||
- name: git-repo | ||
resourceSpec: | ||
type: git | ||
params: | ||
- name: url | ||
value: https://github.com/tektoncd/pipeline.git | ||
params: | ||
- name: filename | ||
value: "README.md" | ||
outputs: | ||
resources: | ||
- name: optionalimage | ||
resourceSpec: | ||
type: image | ||
params: | ||
- name: url | ||
value: gcr.io/foo/bar | ||
taskRef: | ||
name: task-check-optional-resources | ||
--- | ||
|
||
apiVersion: tekton.dev/v1alpha1 | ||
kind: TaskRun | ||
metadata: | ||
name: demo-optional-inputs-resources-invalid-filename | ||
spec: | ||
inputs: | ||
resources: | ||
- name: git-repo | ||
resourceSpec: | ||
type: git | ||
params: | ||
- name: url | ||
value: https://github.com/tektoncd/pipeline.git | ||
params: | ||
- name: filename | ||
value: "invalid.md" | ||
taskRef: | ||
name: task-check-optional-resources | ||
--- | ||
|
||
apiVersion: tekton.dev/v1alpha1 | ||
kind: TaskRun | ||
metadata: | ||
name: demo-optional-inputs-resources-without-resources | ||
spec: | ||
inputs: | ||
params: | ||
- name: filename | ||
value: "README.md" | ||
taskRef: | ||
name: task-check-optional-resources | ||
--- | ||
|
||
apiVersion: tekton.dev/v1alpha1 | ||
kind: TaskRun | ||
metadata: | ||
name: demo-optional-inputs-resources-without-resources-and-params | ||
spec: | ||
taskRef: | ||
name: task-check-optional-resources | ||
--- | ||
|
||
apiVersion: tekton.dev/v1alpha1 | ||
kind: TaskRun | ||
metadata: | ||
name: demo-optional-outputs-resources-with-input-resources | ||
spec: | ||
inputs: | ||
resources: | ||
- name: git-repo | ||
resourceSpec: | ||
type: git | ||
params: | ||
- name: url | ||
value: https://github.com/tektoncd/pipeline.git | ||
params: | ||
- name: filename | ||
value: "README.md" | ||
taskRef: | ||
name: task-check-optional-resources | ||
--- |
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.