簡體   English   中英

如何僅在拉取請求到主分支時運行管道

[英]How to run pipeline only on pull request to master 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:
            - ...

如何根據目標分支進行過濾? 有些測試只有在合並到master時才需要完成。

遺憾的是,拉請求管道機制正在基於源分支而不是在目標分支上工作。

這是由他們的跟蹤器在團隊成員之一添加了pull-request功能的問題上解釋的:

pull請求下的分支模式定義了源分支。 這樣您就可以根據修復運行不同的管道。 例如,您可能對功能分支與修補程序分支具有不同的測試集。 請注意,這只是討論在開發過程中針對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'

或者,如果您已經對所有拉取請求進行了一些測試,就像我理解的那樣:

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

或者再次,它可以自己外部化到腳本:

到位桶,pipelines.yaml

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

斌/測試

#!/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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM