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

Google Cloud Build中使用Secret Manager的curl请求失败求助

解决Google Cloud Build中Slack通知的Secret Manager变量解析问题

问题原因

Notify步骤直接使用curl镜像的args数组传递参数时,$$SLACK_ENDPOINT不会被Shell解析为环境变量值,而是被当作字面量字符串传递给curl,导致curl尝试请求$$SLACK_ENDPOINT这个无效主机,触发「Bad hostname」错误。而Test步骤因为通过bash执行命令,Shell会正确解析环境变量,所以能正常输出URL。

修复后的构建配置

将Notify步骤改为通过bash执行curl命令,让Shell解析环境变量:

steps:
  - name: gcr.io/cloud-builders/gcloud
    id: Test
    entrypoint: bash
    args:
      - -c
      - |
        echo $$SLACK_ENDPOINT
    secretEnv: ['SLACK_ENDPOINT']

  - name: curlimages/curl
    id: Notify
    entrypoint: bash
    args:
      - -c
      - |
        curl -d '{ "text": "channel test" }' -H "Content-type:application/json" -X POST "$SLACK_ENDPOINT"
    secretEnv: ['SLACK_ENDPOINT']

availableSecrets:
  secretManager:
    - env: 'SLACK_ENDPOINT'
      versionName: projects/$PROJECT_ID/secrets/SLACK_ENDPOINT/versions/2

关键修改点

  • 给Notify步骤添加entrypoint: bash,让命令通过Shell执行
  • 将curl的所有参数整合到bash的命令字符串中,用双引号包裹$SLACK_ENDPOINT确保变量被正确解析
  • 去掉原args中转义的反斜杠,因为bash命令字符串里的双引号直接用即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 00:05:20