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

如何在GitHub Workflow步骤名称中嵌入变量值?

在GitHub Workflow步骤名称中使用变量值的解决方法

你遇到的问题是步骤名称里的${{ env.REGISTRY }}变量无法正常渲染,这是YAML解析时的语法问题,以下是两种可行的解决方法:

方法1:用双引号包裹步骤名称

GitHub Actions支持在步骤名称中使用表达式,但需要将整个名称用双引号括起来,确保YAML正确解析表达式内容:

name: Publish
on:
  push:
    branches:
      - main
env:
  REGISTRY: ghcr.io

jobs:
  Publish:
    runs-on: ubuntu-latest
    steps:
      - name: "Log into Container registry ${{ env.REGISTRY }}"
        # 示例:添加docker登录逻辑
        uses: docker/login-action@v2
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

方法2:通过步骤摘要自定义显示标题

如果方法1不生效,还可以通过run步骤将带变量的标题写入步骤摘要,在Workflow运行结果中展示自定义标题:

name: Publish
on:
  push:
    branches:
      - main
env:
  REGISTRY: ghcr.io

jobs:
  Publish:
    runs-on: ubuntu-latest
    steps:
      - name: Log into Container registry
        run: |
          # 将带变量的标题写入步骤摘要
          echo "### Log into Container registry ${{ env.REGISTRY }}" >> $GITHUB_STEP_SUMMARY
        uses: docker/login-action@v2
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 07:51:11