gpt4 book ai didi

git - 如何仅在对主分支的 pull 请求时运行管道

转载 作者:太空狗 更新时间:2023-10-29 13:54:23 25 4
gpt4 key购买 nike

Bitbucket 管道允许定义对 pull 请求的检查,并具有允许检查源分支的 glob 过滤器。

pipelines:
pull-requests:
'**': #this runs as default for any branch not elsewhere defined
- step:
script
- ...
feature/*: #any branch with a feature prefix
- step:
script:
- ...

如何根据目标分支过滤?有些测试只有在 merge 到master时才需要做。

最佳答案

遗憾的是, pull 请求管道机制是基于源分支而不是目标分支工作的。

这在他们的跟踪器中由一名团队成员添加了 pull-request 功能的问题上进行了解释:

The branch pattern under pull requests defines the source branch. Thisis so that you can run a different pipeline depending on the fix. Forexample you may have a different set of tests for feature branches vshotfix branches. Note that this is only talking about the tests thatrun against the PR during development.

来源: Geoff Crain's comment

实际上还有一个问题是 this exact feature。 .

但是团队的回答是:

I can definitely see why this would be useful, especially when mergingto the master/main branch.

Given our current priorities, however, this is unlikely something thatwe'll support in the short term. In the meantime though, I'll openthis ticket to gauge the interest of other users in seeing the samething.

来源:Aneita Yang's comment

也就是说,您可以通过这种 hack 以某种方式获得所需的行为:

pipelines:
pull-requests:
'**': #this runs as default for any branch not elsewhere defined
- step:
script
- if [ "${BITBUCKET_PR_DESTINATION_BRANCH}" != "master" ]; then printf 'not a target branch we want to check'; exit; fi
- printf 'running useful tests'

或者,如果您已经在对所有 pull 请求进行一些测试,就像我理解的那样:

pipelines:
pull-requests:
'**': #this runs as default for any branch not elsewhere defined
- step:
script
- printf 'these are the all PR tests'
- if [ "${BITBUCKET_PR_DESTINATION_BRANCH}" = "master" ]; then printf 'those are the extra checks on master'; fi

或者,它可以自己外化到脚本中:

bitbucket-pipelines.yaml

pipelines:
pull-requests:
'**': #this runs as default for any branch not elsewhere defined
- step:
script
- ./bin/tests "${BITBUCKET_PR_DESTINATION_BRANCH}"

bin/测试

#!/usr/bin/env bash

printf 'these are the all PR tests'

if [ "${1}" = "master" ]
then
printf 'those are the extra checks on master'
fi

另请参阅:管道文档页面中的变量:https://confluence.atlassian.com/bitbucket/variables-in-pipelines-794502608.html

关于git - 如何仅在对主分支的 pull 请求时运行管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55019205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com