apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
  generateName: steptemplate-env-merge-
spec:
  params:
  - name: FOO
    value: foo
  - name: BAR
    value: bar
  taskSpec:
    # This template will be applied to all steps
    stepTemplate:
      env:
      - name: QUX
        value: original
    params:
    - name: FOO
      description: FOO variable
    - name: BAR
      description: BAR variable
    - name: FOOBAR
      description: FOOBAR variable
      default: foobar
    steps:
      # Test the environment variables are set in the task
      - name: foo
        image: public.ecr.aws/ubuntu/ubuntu:latest
        script: |
          #!/usr/bin/env bash
          [[ $FOO == "foo" ]]
        env:
        - name: FOO
          value: $(params.FOO)
      - name: foobar
        image: public.ecr.aws/ubuntu/ubuntu:latest
        script: |
          #!/usr/bin/env bash
          [[ $FOOBAR == "foobar" ]]
        env:
        - name: FOOBAR
          value: $(params.FOOBAR)
      - name: bar
        image: public.ecr.aws/ubuntu/ubuntu:latest
        script: |
          #!/usr/bin/env bash
          [[ $BAR == "bar" ]]
        env:
        - name: BAR
          value: $(params.BAR)
      # Use the env var from the stepTemplate
      - name: qux-no-override
        image: public.ecr.aws/ubuntu/ubuntu:latest
        script: |
          #!/usr/bin/env bash
          [[ $QUX == "original" ]]
      # Override the env var in the stepTemplate
      - name: qux-override
        image: public.ecr.aws/ubuntu/ubuntu:latest
        script: |
          #!/usr/bin/env bash
          [[ $QUX == "override" ]]
        env:
        - name: QUX
          value: override
