apiVersion: tekton.dev/v1alpha1
kind: Condition
metadata:
  name: condition-1
spec:
  check:
    args:
    - EXITCODE=$(python -c "import sys; input1=str.rstrip(sys.argv[1]); input2=str.rstrip(sys.argv[2]); print(0) if (input1 == 'heads') else
      print(1)" '$(params.flip-coin)' 'heads'); exit $EXITCODE
    command:
    - sh
    - -c
    image: python:alpine3.6
  params:
  - name: flip-coin
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: flip-coin
spec:
  results:
  - description: /tmp/output
    name: output
  steps:
  - args:
    - python -c "import random; result = 'heads' if random.randint(0,1) == 0 else
      'tails'; result='heads'; print(result)" | tee $(results.output.path)
    command:
    - sh
    - -c
    image: python:alpine3.6
    name: flip-coin
---
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
  name: condition-check
spec:
  params:
  - name: flip-coin
  results:
  - description: /tmp/output
    name: output
  steps:
  - args:
    - EXITCODE=$(python -c "import sys; input1=str.rstrip(sys.argv[1]); input2=str.rstrip(sys.argv[2]); print(input1) if (input1 == 'heads') else
      print(input1)" '$(params.flip-coin)' 'heads'); echo $EXITCODE | tee $(results.output.path)
    command:
    - sh
    - -c
    image: python:alpine3.6
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: generate-random-number
spec:
  results:
  - description: /tmp/output
    name: output
  steps:
  - args:
    - python -c "import random; print(random.randint($0, $1))" | tee $2
    - '0'
    - '9'
    - $(results.output.path)
    command:
    - sh
    - -c
    image: python:alpine3.6
    name: generate-random-number
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  annotations:
    pipelines.kubeflow.org/pipeline_spec: '{"description": "Shows how to use dsl.Condition().",
      "name": "Conditional execution pipeline"}'
  name: flip-cond-gen-pipeline
spec:
  params: []
  tasks:
  - name: flip-coin
    params: []
    taskRef:
      name: flip-coin
  - name: condition-check
    params:
      - name: flip-coin
        value: $(tasks.flip-coin.results.output)
    taskRef:
      name: condition-check
  - conditions:
    - conditionRef: condition-1
      params:
      - name: flip-coin
        value: $(tasks.flip-coin.results.output)
    name: generate-random-number
    params: []
    taskRef:
      name: generate-random-number
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  name: flip-cond-gen-pipeline-run
spec:
  pipelineRef:
    name: flip-cond-gen-pipeline