-
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.
Enabling Pipeline Resources to be marked as Optional
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 PipelineDeclaredResource similar to previous PR #1601, by default optional is set to false and 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: resources: - name: workspace type: git optional: true tasks: - name: check-workspace Closes #1710
- Loading branch information
1 parent
ab43a6a
commit 5fb1297
Showing
5 changed files
with
289 additions
and
17 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
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,128 @@ | ||
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 | ||
script: '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 | ||
script: '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