You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在GitHub Actions工作流YAML中引用部署环境名称?

在GitHub Actions工作流中获取部署环境名称

你可以使用github.environment上下文变量来获取当前job指定的环境名称,直接替换示例中的????即可。

修改后的完整代码如下:

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

    steps:
      ...
      - name: Terraform Check Format
        id: terraform-fmt
        run: terraform -chdir=terraform/stacks/${{ github.environment }}/${{ matrix.stack }} fmt -check

补充说明

  • github.environment会直接返回当前job中定义的环境名称,比如示例里的foobarbaz
  • 如果当前job未指定环境,该变量会返回空字符串

内容的提问来源于stack exchange,提问作者Joohwan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 08:10:37