forked from tektoncd/pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Resources to be Optional in Pipeline
Pipeline inputs and outputs are considered required, there is no way today to mark them optional. This change introduces a new field called optional as part of the PipelineTaskInputResource and PipelineTaskOutputResource by default a resource is required. To mark any resource optional, set optional to true: apiVersion: tekton.dev/v1alpha1 kind: Pipeline metadata: name: pipeline-build-image spec: inputs: resources: - name: workspace type: git optional: true tasks: - name: check-workspace Closes tektoncd#1710
- Loading branch information
1 parent
2af394c
commit f22bfb1
Showing
7 changed files
with
320 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Condition | ||
metadata: | ||
name: check-git-pipeline-resource | ||
spec: | ||
params: | ||
- name: "path" | ||
resources: | ||
- name: git-repo | ||
type: git | ||
optional: true | ||
check: | ||
image: alpine | ||
command: ["/bin/sh"] | ||
args: ['-c', 'test -f $(resources.git-repo.path)/$(params.path)'] | ||
--- | ||
|
||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Condition | ||
metadata: | ||
name: check-image-pipeline-resource | ||
spec: | ||
resources: | ||
- name: built-image | ||
type: image | ||
optional: true | ||
check: | ||
image: alpine | ||
command: ["/bin/sh"] | ||
args: ['-c', 'test ! -z $(resources.built-image.url)'] | ||
--- | ||
|
||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Task | ||
metadata: | ||
name: build-an-image | ||
spec: | ||
inputs: | ||
resources: | ||
- name: git-repo | ||
type: git | ||
optional: true | ||
params: | ||
- name: DOCKERFILE | ||
description: The path to the dockerfile to build from GitHub Repo | ||
default: "Dockerfile" | ||
outputs: | ||
resources: | ||
- name: built-image | ||
type: image | ||
optional: true | ||
steps: | ||
- name: build-an-image | ||
image: "gcr.io/kaniko-project/executor:latest" | ||
command: | ||
- /kaniko/executor | ||
args: | ||
- --dockerfile=$(inputs.params.DOCKERFILE) | ||
- --destination=$(outputs.resources.built-image.url) | ||
--- | ||
|
||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Pipeline | ||
metadata: | ||
name: demo-pipeline-to-build-an-image | ||
spec: | ||
resources: | ||
- name: source-repo | ||
type: git | ||
optional: true | ||
- name: web-image | ||
type: image | ||
optional: true | ||
params: | ||
- name: "path" | ||
default: "README.md" | ||
tasks: | ||
- name: build-an-image | ||
taskRef: | ||
name: build-an-image | ||
conditions: | ||
- conditionRef: "check-git-pipeline-resource" | ||
params: | ||
- name: "path" | ||
value: "$(params.path)" | ||
resources: | ||
- name: git-repo | ||
resource: source-repo | ||
- conditionRef: "check-image-pipeline-resource" | ||
resources: | ||
- name: built-image | ||
resource: web-image | ||
resources: | ||
inputs: | ||
- name: git-repo | ||
resource: source-repo | ||
outputs: | ||
- name: built-image | ||
resource: web-image | ||
|
||
--- | ||
|
||
apiVersion: tekton.dev/v1alpha1 | ||
kind: PipelineRun | ||
metadata: | ||
name: demo-pipeline-run-1 | ||
spec: | ||
pipelineRef: | ||
name: demo-pipeline-to-build-an-image | ||
serviceAccountName: 'default' | ||
--- | ||
|
||
apiVersion: tekton.dev/v1alpha1 | ||
kind: PipelineRun | ||
metadata: | ||
name: demo-pipeline-run-2 | ||
spec: | ||
pipelineRef: | ||
name: demo-pipeline-to-build-an-image | ||
serviceAccountName: 'default' | ||
resources: | ||
- name: source-repo | ||
resourceSpec: | ||
type: git | ||
params: | ||
- name: revision | ||
value: master | ||
- name: url | ||
value: https://github.com/tektoncd/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
Oops, something went wrong.