合并时如何从谷歌云构建触发器获取源分支

发布于 2025-01-15 08:12:58 字数 347 浏览 3 评论 0原文

我正在将 github 拉取请求中的“feature-branch”合并到“dev-branch”上。我正在使用谷歌云构建触发器,该触发器在推送到“dev-branch”时触发。据我所知,替换变量文档,没有替代变量来获取我要合并的分支的名称 - 'feature-branch',只有我合并到的分支 - 'dev-branch'。有没有办法或解决方法来获取从推送到分支事件的谷歌云构建触发器上合并的分支的信息(名称、sha、id 等)?

I am merging 'feature-branch' onto 'dev-branch' from a github pull request. I am using a google cloud build trigger that is triggered on push to 'dev-branch'. From what I can tell in the documentation of substitution variables, there are no substitution variables to get the name of the branch that I am merging from - 'feature-branch' and only the branch that I merging to - 'dev-branch'. Is there a way or a workaround to get information (name, sha, id, etc.) of the branch that is being merged from on a google cloud build trigger from a push to branch event?

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

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

发布评论

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

评论(1

忆伤 2025-01-22 08:12:58

据推测,您可以在提交消息的第一行(发生在合并拉取请求“事件”时)有一些命名约定,以便该行包含源(或头) )分支名称(合并的来源 - 用你的话来说 - 'feature-branch')。

然后,您可以创建一个替换变量:

substitutions:
  _COMMIT_MESSAGE: $(commit.commit.message)

这是一个文档链接:使用负载绑定创建替换

并在某个构建步骤中使用该变量来获取 head 分支名称:

    mapfile -t commit_lines <<< "${_COMMIT_MESSAGE}"
    source_branch="$(echo ${commit_lines[0]} | <<add your command here following naming convention for the commit message>> )"
    echo "=> My source branch name: ${source_branch}"

之后您可以使用源分支名称。

Presumably you can have some naming conventions on the first line of the commit message (happens at merge pull request "event"), so that this line includes the source (or head) branch name (the source of the merge - in your words - 'feature-branch').

Then, you can create a substitution variable:

substitutions:
  _COMMIT_MESSAGE: $(commit.commit.message)

here is a documentation link: Creating substitutions using payload bindings

And use that variable in some build step to get the the head branch name:

    mapfile -t commit_lines <<< "${_COMMIT_MESSAGE}"
    source_branch="$(echo ${commit_lines[0]} | <<add your command here following naming convention for the commit message>> )"
    echo "=> My source branch name: ${source_branch}"

After that you can use the source branch name.

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