【问题标题】:Is there a way to get the Github Pull Request number during a build of Google Cloud Build?有没有办法在构建 Google Cloud Build 期间获取 Github Pull Request 编号?
【发布时间】:2023-04-05 01:42:01
【问题描述】:

在 Google Cloud 构建期间,有没有办法获取有关构建与拉取请求(例如拉取请求编号/ID)相关联的信息?

目前似乎没有这样的替代变量可用参考:https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values

【问题讨论】:

    标签: google-cloud-build


    【解决方案1】:

    在 GitHub 中,一个分支可以关联多个 Pull Request。

    您可以使用 GitHub API 查找与给定分支 ref 关联的所有 PR:https://developer.github.com/v3/pulls/

    Cloud Build 当前不提供拉取请求信息,但如果提供,则可能来自 Check Suite 数据之类的数据,该数据也将 PR 视为列表。

    【讨论】:

    • 非常感谢您的指点。实际上,我认为目前 GCB Github 应用程序不支持 PR 事件,我将不得不破解并希望(或/和检测)该分支仅匹配一个 PR。
    【解决方案2】:

    不是来自 Github API,但你可以从命令行获取 PR#:

    $ hub pr list -f "%I%n" -h "$(git rev-parse --abbrev-ref HEAD)"
    12345
    

    来源:这个blog post

    【讨论】:

      【解决方案3】:

      现在它们可用作 CloudBuild 环境变量。来自官方文档:

      Cloud Build 提供以下 GitHub 特定的默认值 可用于拉取请求触发器的替换:

      $_HEAD_BRANCH : head branch of the pull request
      $_BASE_BRANCH : base branch of the pull request
      $_HEAD_REPO_URL : url of the head repo of the pull request
      $_PR_NUMBER : number of the pull request
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-06-21
        • 2019-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-03
        相关资源
        最近更新 更多