Nested Variables

Hello All,

Trying to figure out how to use a Variable within a variable. Example shown below:


Not sure if the ${{ env: }} is needed or if I should be using a different format for the nested variable.

First of, there are two format errors in your example:

  1. To define variables in YAML you need to use :, not =. In most cases the quotes are optional, though.
  2. The variable references lack the $ before {{.

However, I’m not sure if you can reference environment variables in the env definitions at job level. At step level it definitely does not work, because there env only defines environment variables for that step, they are not added to the job-wide environment.

If you want to use the job-wide environment you can try setting the referenced variables using set-env commands:

      - name: set name parts
        run: |
          echo "::set-env name=FirstName::John"
          echo "::set-env name=LastName::Doe"
      - name: echo full name
        run: |
          echo "${FullName}"
          FullName: '${{ env.FirstName }}.${{ env.LastName }}'

Thank you airtower-luna. I’m new to YAML so I appreciate the explanation. I will try within environment.

1 Like