如何仅在对主分支的拉取请求上运行管道

Mar*_*ala 5 git bitbucket bitbucket-pipelines

Bitbucket管道允许定义对拉取请求的检查,并具有全局过滤器,可以检查源分支。

pipelines:
  pull-requests:
    '**': #this runs as default for any branch not elsewhere defined
      - step:
          script
            - ...
    feature/*: #any branch with a feature prefix
      - step:
          script:
            - ...
Run Code Online (Sandbox Code Playgroud)

如何根据目标分支进行过滤?只有合并到母版中时,才需要执行一些测试。

β.ε*_*.βε 7

确实令人遗憾的是,拉取请求管道机制是基于源分支而不是目标分支运行的。

这是pull-request由团队成员之一通过其跟踪器添加功能来解决的:

拉取请求下的分支模式定义了源分支。这样,您可以根据修复程序运行不同的管道。例如,对于功能分支与修补程序分支,您可能具有一组不同的测试。注意,这仅是在开发过程中针对PR运行的测试。

资料来源:Geoff Crain的评论

确切的功能实际上还有另一个问题。

但是团队的答案是:

我绝对可以理解为什么这会很有用,尤其是在合并到master / main分支时。

但是,考虑到我们当前的优先事项,短期内不太可能支持。不过,与此同时,我将打开此票证以评估其他用户对看到同一事物的兴趣。

资料来源Aneita Yang的评论

就是说,您可以通过某种方式以某种方式具有所需的行为:

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'
Run Code Online (Sandbox Code Playgroud)

或者,如果您已经对所有拉取请求进行了一些测试,如我所知:

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
Run Code Online (Sandbox Code Playgroud)

还是可以再次将其自身外部化为脚本:

bitbucket-pipelines.yaml

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

箱/测试

#!/usr/bin/env bash

printf 'these are the all PR tests'

if [ "${1}" = "master" ]
then 
    printf 'those are the extra checks on master'
fi
Run Code Online (Sandbox Code Playgroud)

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