apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
  generateName: steptemplate-env-merge-
spec:
  inputs:
    params:
    - name: FOO
      value: foo
    - name: BAR
      value: bar
  taskSpec:
    # This template will be applied to all steps
    stepTemplate:
      env:
      - name: QUX
        value: original
    inputs:
      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: ubuntu
        script: |
          #!/usr/bin/env bash
          [[ $FOO == "foo" ]]
        env:
        - name: FOO
          value: $(inputs.params.FOO)
      - name: foobar
        image: ubuntu
        script: |
          #!/usr/bin/env bash
          [[ $FOOBAR == "foobar" ]]
        env:
        - name: FOOBAR
          value: $(inputs.params.FOOBAR)
      - name: bar
        image: ubuntu
        script: |
          #!/usr/bin/env bash
          [[ $BAR == "bar" ]]
        env:
        - name: BAR
          value: $(inputs.params.BAR)
      # Use the env var from the stepTemplate
      - name: qux-no-override
        image: ubuntu
        script: |
          #!/usr/bin/env bash
          [[ $QUX == "original" ]]
      # Override the env var in the stepTemplate
      - name: qux-override
        image: ubuntu
        script: |
          #!/usr/bin/env bash
          [[ $QUX == "override" ]]
        env:
        - name: QUX
          value: override
