GitHub Actions: env: Use pre-defined environment variables on RHS within env section

edb*_*rns 3 github-actions

I would like to declare some environment variables in a top level env section in my main.yml whose values use some pre-defined environment variables such as those documented in the GitHub Actions documentation. However, it appears I cannot use those pre-defined variables in the right hand side of my env section. For example:

env:
  resourceGroup: ${GITHUB_RUN_ID}${GITHUB_RUN_NUMBER}
Run Code Online (Sandbox Code Playgroud)

Is there a way to make it so any step that needs ${resourceGroup} can get it without having to manually define it within each step?

ban*_*yan 17

我尝试了以下两种方法。

env:
  resourceGroup1: ${GITHUB_RUN_ID}-${GITHUB_RUN_NUMBER}
  resourceGroup2: ${{ github.run_id }}-${{ github.run_number }}

jobs:
  foo:
    runs-on: ubuntu-latest
    steps:
      - name: test1
        run: echo ${{ env.resourceGroup1 }}
      - name: test2
        run: echo ${{ env.resourceGroup2 }}
Run Code Online (Sandbox Code Playgroud)

在这两种情况下,结果都得到了正确的结果。

在此处输入图片说明

但是,在结果为 env 的情况下,尚未评估前者。也许你可以使用后者。

在此处输入图片说明