替换变量 $BRANCH_NAME 在构建时什么都不给

substitution variable $BRANCH_NAME gives nothing while building

我正在使用 Cloud Builder 触发器构建 docker 图像,之前 $BRNACH_NAME 可以正常工作,但现在它给出了 null。

提前致谢。

我会 post 我的评论作为答案,因为评论部分太长了。

根据 this documentation,您应该可以使用 $BRANCH_NAME 默认替换构建由触发器调用。

在同一文档中指出:

If a default substitution is not available (such as with sourceless builds, or with builds that use storage source), then occurrences of the missing variable are replaced with an empty string.

我想这可能是您收到 NULL.

的原因

您是否进行了任何更改?您能否提供一些进一步的信息,例如您的 .yaml/.json 文件、您的触发器配置和您收到的错误?

问题不在 $BRANCH_NAME,我正在使用结果 JSON 来获取分支名称。

喜欢,

"source": {
    "repoSource": {
      "projectId": "project_id",
      "repoName": "bitbucket_repo_name",
      "branchName": "integration"
    }
  }

和 我正在使用 build_details['source']['repoSource']['branchName']

但现在它给了赞

"source": {
    "repoSource": {
      "projectId": "project_id",
      "repoName": "bitbucket_repo_name",
      "commitSha": "ght8939jj5jd9jfjfjigk0949jh8wh4w"
    }
  },

所以,现在我正在使用 build_details['substitutions']['BRANCH_NAME'],它工作正常。