3

I would like to access the deployment environment name in my Github Actions workflow YAML. Here is an example:

jobs:
  example:
    runs-on: ubuntu-latest
    environment: "foobarbaz"
    ...

    steps:
      ...
      - name: Terraform Check Format
        id: terraform-fmt
        # what should I use here instead of "????" to get "foobarbaz"?
        run: terraform -chdir=terraform/stacks/${{ ???? }}/${{ matrix.stack }} fmt -check
Joohwan
  • 2,374
  • 1
  • 19
  • 30

1 Answers1

0

As jobs context is only available in reusable workflows one of working option could be use env:

name: question-74910046
# https://stackoverflow.com/questions/74910046/how-do-i-reference-the-deployment-environment-name-in-github-actions-workflow-ya

on:
  workflow_dispatch:
  
env:
  env_name: production-74910046
  env_url: https://stackoverflow.com/questions/74910046/how-do-i-reference-the-deployment-environment-name-in-github-actions-workflow-ya

jobs:
  test:
    runs-on: ubuntu-latest

    environment: 
      name: $env_name
      url: $env_url
    
    steps:
      - name: context information
        run: echo '${{ toJSON(env) }}'
BLuM
  • 657
  • 5
  • 28