[英]How to run pipeline only on pull request to master branch
Bitbucket pipelines allows to define checks on pull-requests and has glob filter that allows checking source branch. Bitbucket管道允许定义对pull-requests的检查,并具有允许检查源分支的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:
- ...
How to filter based on target branch? 如何根据目标分支进行过滤? There are some tests that need to be done only when merging into master.
有些测试只有在合并到master时才需要完成。
Sadly indeed, the pull-request pipeline mechanism is working based on the source branch, not on the target branch. 遗憾的是,拉请求管道机制正在基于源分支而不是在目标分支上工作。
This is explained on the issue from their tracker adding the pull-request
feature by one of the team member: 这是由他们的跟踪器在团队成员之一添加了
pull-request
功能的问题上解释的:
The branch pattern under pull requests defines the source branch.
pull请求下的分支模式定义了源分支。 This is so that you can run a different pipeline depending on the fix.
这样您就可以根据修复运行不同的管道。 For example you may have a different set of tests for feature branches vs hotfix branches.
例如,您可能对功能分支与修补程序分支具有不同的测试集。 Note that this is only talking about the tests that run against the PR during development.
请注意,这只是讨论在开发过程中针对PR运行的测试。
Source: Geoff Crain's comment 资料来源: Geoff Crain的评论
There is actually another issue open for this exact feature . 这个确切的功能实际上还有另一个问题。
But the answer from the team is: 但团队的答案是:
I can definitely see why this would be useful, especially when merging to the master/main branch.
我可以肯定地知道为什么这会有用,特别是在合并到master / main分支时。
Given our current priorities, however, this is unlikely something that we'll support in the short term.
然而,鉴于我们目前的优先事项,我们不太可能在短期内支持这一点。 In the meantime though, I'll open this ticket to gauge the interest of other users in seeing the same thing.
与此同时,我会打开这张票来衡量其他用户对同样事情的兴趣。
Source : Aneita Yang's comment 资料来源 : Aneita Yang的评论
That said, you could somehow have the required behavior with this kind of 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'
Or, if you already are doing some tests on all pull request, like I understand it: 或者,如果您已经对所有拉取请求进行了一些测试,就像我理解的那样:
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
Or yet again, it could be externalized to a script on its own: 或者再次,它可以自己外部化到脚本:
bitbucket-pipelines.yaml 到位桶,pipelines.yaml
pipelines:
pull-requests:
'**': #this runs as default for any branch not elsewhere defined
- step:
script
- ./bin/tests "${BITBUCKET_PR_DESTINATION_BRANCH}"
bin/tests 斌/测试
#!/usr/bin/env bash
printf 'these are the all PR tests'
if [ "${1}" = "master" ]
then
printf 'those are the extra checks on master'
fi
See also : Variables in pipelines documentation page: https://confluence.atlassian.com/bitbucket/variables-in-pipelines-794502608.html 另请参见 :管道文档中的变量文档页面: https : //confluence.atlassian.com/bitbucket/variables-in-pipelines-794502608.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.