简体   繁体   English

如何仅在拉取请求到主分支时运行管道

[英]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.

相关问题 Azure 管道在拉取请求分支上运行构建 - Azure pipeline run build on Pull Request branch 如何将master合并为作为pull request提交的分支? - How to merge master into branch submitted as pull request? 如何接受对分支机构的拉取请求(在 master 上完成)? - How to accept a pull request (done on master) to a branch? 如何在GitHub中只使用我的分叉存储库的主分支中的最新提交来执行拉取请求 - How to do a pull request in GitHub with only the latest commit in the master branch of my forked repository 仅当从 GitHub 中的特定分支发出拉取请求时,如何触发 Jenkins 管道? - How to trigger a Jenkins pipeline only when a pull request is made from a specific branch in GitHub? 如果拉取请求在 fork 主分支上,如何找到它的启动 SHA - How to find a Pull Request start SHA if it is on the fork master branch 如何在主分支的第一个版本上创建 Github 拉取请求 - How to create Github pull request on first version of master branch 如何使用Sourcetree NOT在主分支中进行自动拉取请求? - How to make automatic pull request with Sourcetree NOT in master branch? 如何从主分支向暂存分支发出拉取请求? - How do I make a pull request from the master to the staging branch? 如何在 Azure DevOps 的管道中向远程分支发出拉取请求? - How to make a pull request to a remote branch in a pipeline in Azure DevOps?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM