GitHub动作中的环境变量未正确插值

发布于 2025-02-07 08:45:56 字数 920 浏览 2 评论 0原文

在(可重复使用的)工作流程的开头

env:
  STAGING_GCR_PROJECT: my-project-id

,在Slack中使用它时,

  slack_staging_success:
    needs: build_staging
    runs-on: ubuntu-latest
    if: ${{ always() && contains(join(needs.*.result, ','), 'success') }}
    env:
      STAGING_IMAGE: "gcr.io/$STAGING_GCR_PROJECT/${{ inputs.image_name }}:${{ inputs.image_tag }}"

    
    steps:
      
    - name: slack success for staging
      uses: rtCamp/action-slack-notify@v2
      env:
        SLACK_ICON: $SLACK_ICON_SUCCESS
        SLACK_COLOR: green
        SLACK_MESSAGE: "STAGING image ${{ env.STAGING_IMAGE }} was built / pushed with SUCCESS"

消息插值为

登台图像gcr.io/qulstaging_gcr_project/echo-server:1.0.2无法构建

为什么$ staging_gcr_project不正确地进行了插补?

In the beginning of a (re-usable) workflow

env:
  STAGING_GCR_PROJECT: my-project-id

and when using it

  slack_staging_success:
    needs: build_staging
    runs-on: ubuntu-latest
    if: ${{ always() && contains(join(needs.*.result, ','), 'success') }}
    env:
      STAGING_IMAGE: "gcr.io/$STAGING_GCR_PROJECT/${{ inputs.image_name }}:${{ inputs.image_tag }}"

    
    steps:
      
    - name: slack success for staging
      uses: rtCamp/action-slack-notify@v2
      env:
        SLACK_ICON: $SLACK_ICON_SUCCESS
        SLACK_COLOR: green
        SLACK_MESSAGE: "STAGING image ${{ env.STAGING_IMAGE }} was built / pushed with SUCCESS"

In Slack the message interpolates as

STAGING image gcr.io/$STAGING_GCR_PROJECT/echo-server:1.0.2 failed to be built

Why isn't $STAGING_GCR_PROJECT interpolated correctly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九八野马 2025-02-14 08:45:56

目前不支持ENV变量Ins Inv。

docs> docs 提到:

env映射中的变量无法根据地图中的其他变量来定义。

It is not supported at the moment, to have env variable inside env.

The docs on env mentions it:

variables in the env map cannot be defined in terms of other variables in the map.

失去的东西太少 2025-02-14 08:45:56

为了使用工作流环境变量,请使用前缀env。

env:
  STAGING_IMAGE: "gcr.io/${{ env.STAGING_GCR_PROJECT }}/${{ inputs.image_name }}:${{ inputs.image_tag }}"

In order to use workflow environment variables, use the prefix env. and enclose it in ${{ }} just like you did with the inputs:

env:
  STAGING_IMAGE: "gcr.io/${{ env.STAGING_GCR_PROJECT }}/${{ inputs.image_name }}:${{ inputs.image_tag }}"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文