전자책 출간 알림 [마이크로서비스패턴 쉽게 개발하기]

티스토리 뷰

Agile&DevOps/Tekton

6. Conditions

Happy@Cloud 2019. 12. 13. 21:13

아래 소스를 test-condition.yaml로 저장하십시오.

apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
  name: pipeline-git
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-files
spec:
  inputs:
    resources:
    - name: workspace
      type: git
  steps:
  - name: run-ls
    image: ubuntu
    command:
    - /bin/bash
    args:
    - -c
    - ls -al $(inputs.resources.workspace.path)

---
apiVersion: tekton.dev/v1alpha1
kind: Condition
metadata:
  name: file-exists
spec:
  check:
    image: alpine
    command:
    - /bin/sh
    args:
    - -c
    - test -f $(resources.workspace.path)/$(params.path)
  params:
  - name: path
  resources:
  - name: workspace
    type: git
---
apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
  name: list-files-pipeline
spec:
  params:
  - default: README.md
    name: path
    type: string
  resources:
  - name: source-repo
    type: git
  tasks:
  - name: list-files-1
    taskRef:
      name: list-files
    resources:
      inputs:
      - name: workspace
        resource: source-repo
    conditions:
    - conditionRef: file-exists
      params:
      - name: path
        value: $(params.path)
      resources:
      - name: workspace
        resource: source-repo

---
apiVersion: tekton.dev/v1alpha1
kind: PipelineRun
metadata:
  name: demo-condtional-pr
spec:
  serviceAccountName: default
  pipelineRef:
    name: list-files-pipeline
  resources:
  - name: source-repo
    resourceRef:
      name: pipeline-git

pipeline에서 넘기는 README.md파일이 있는지 condition에서 검사하여 그 결과에 따라 Task를 실행하거나 하지 않습니다.

실행해 봅시다.

$ kubectl apply -f test-condition.yaml

$ watch tkn pr list 

$ tkn pr logs demo-condtional-pr

위와 비슷하게 파일 list가 표시될겁니다.

 

자  이번엔 task가 실행안되도록, pipeline의 README.md를 README2.md로 바꾸고 다시 실행해 봅시다.

$ tkn pr delete demo-condtional-pr

$ kubectl apply -f test-condition.yaml

$ watch tkn pr list

$ tkn pr logs demo-condtional-pr

이젠 task가 실행되지 않아 위와 같은 로그가 나올것입니다.

'Agile&DevOps > Tekton' 카테고리의 다른 글

7. Tekton trigger  (0) 2019.12.16
5. Pipeline Resource  (0) 2019.12.13
4. Pipeline & PipelineRun  (0) 2019.12.13
3. Task & TaskRun  (0) 2019.12.13
2. Tekton 설치하기  (0) 2019.12.13
댓글

전자책 출간 알림 [마이크로서비스패턴 쉽게 개발하기]