Environment name via step output variable not possible

Hi,

dependent of an environment variable, I would like to set the name of the environment:

jobs:
  ci:
    runs-on: ubuntu-20.04
    environment:
      name: ${{ steps.deploy.outputs.STAGE }}
      url: ${{ steps.deploy.outputs.API_URL }}

    steps:
      - name: Set dev stage
        run: |
          echo "STAGE=dev" >> $GITHUB_ENV
      - name: Overwrite stage to prod
        if: endsWith(github.ref, '/prod')
        run: |
          echo "STAGE=prod" >> $GITHUB_ENV

      - name: Deploy to ${{env.STAGE}}
        id: deploy
        run: |
          npm run deploy
          echo "::set-output name=API_URL::$(SOME_COMMAND)
          echo "::set-output name=STAGE::${{env.STAGE}}

If I do so, I get an error that steps is not available in the environment name. Referencing steps in the environment url works.

The workflow is not valid. .github/workflows/ci.yml (Line: 20, Col: 13): Unrecognized named-value: 'steps'. Located at position 1 within expression: steps.deploy.outputs.STAGE

Is there a solution for this problem?

Best,
Fabian

1 Like

Youre using steps before it’s defined? It’s a race condition thing I think