I want to set an environment variable in the env:
section of a GitHub Action and make use of the Contexts and expression syntax for GitHub Actions. I tried this:
jobs:
build:
runs-on: ubuntu-latest
env:
MYVAR: ${{ format('{0}:{1}', ${{ env.PATH }}, ${{ env.HOME }} ) }}
steps:
- name: Check environment
run: echo $MYVAR
This results in the error message:
### ERRORED 10:45:52Z
- Your workflow file was invalid: The pipeline is not valid. .github/workflows/main.yml (Line: 10, Col: 14): Unexpected symbol: '${{'. Located at position 19 within expression: format('{0}:{1}', ${{ env.PATH
This syntax:
env:
MYVAR: ${{ format('{0}:{1}', {{ env.PATH }}, {{ env.HOME }} ) }}
results in error:
### ERRORED 13:14:18Z
- Your workflow file was invalid: The pipeline is not valid. .github/workflows/main.yml (Line: 10, Col: 14): Unexpected symbol: '{{'. Located at position 19 within expression: format('{0}:{1}', {{ env.PATH
and:
env:
MYVAR: ${{ format('{0}:{1}', env.PATH, env.HOME ) }}
results in error:
### ERRORED 13:16:12Z
- Your workflow file was invalid: The pipeline is not valid. .github/workflows/main.yml (Line: 10, Col: 14): Unrecognized named-value: 'env'. Located at position 19 within expression: format('{0}:{1}', env.PATH, env.HOME )
I'm aware of the solutions in How do i set an env var with a bash expression in GitHub Actions? and Github Actions, how to share a calculated value between job steps? for setting environment variables, but I would like to understand the expression syntax.