我正在嘗試設定一個僅構建主分支和主分支的管道模板目錄。
如果我只定義一個分支名稱,例如master說我想要NoTriggerBranchPropertyfor everything ,它就可以作業not master。我的template.yaml檔案的相關部分:
multibranch:
branchSource:
git:
remote: '${repo}'
credentialsId: '${credentialsId}'
strategy:
$class: NamedExceptionsBranchPropertyStrategy
namedExceptions:
- name: "!master"
props:
- $class: NoTriggerBranchProperty
buildStrategies:
- $class: SkipInitialBuildOnFirstBranchIndexing
根據檔案,我可以附加名稱,所以!master,!main應該可以,但它沒有。它實際上使所有分支都不會在 SCM 更改時觸發。
我更進一步,查看了 Cloudbees在這里使用的匹配代碼,據我所知!master,!main應該可以正常作業。我懷疑我的程序中有一個邏輯錯誤,因為我試圖在使用 no trigger 屬性時反轉分支名稱以觸發它們。
uj5u.com熱心網友回復:
經過整整8個小時的測驗,我終于解決了這個問題。
查看 NamedExceptionsBranchPropertyStrategy 代碼,很明顯它!main,!master不會起作用,因為NamedExceptionsBranchPropertyStrategy.isMatch作為||兩個名稱的函式。因此,在此示例中!main回傳名字,true并且由于它是匹配的,因此它破壞了整個邏輯鏈。
相反,解決方案是
multibranch:
branchSource:
git:
remote: '${repo}'
credentialsId: '${credentialsId}'
strategy:
$class: NamedExceptionsBranchPropertyStrategy
namedExceptions:
- name: "master,main"
defaultProperties:
- $class: NoTriggerBranchProperty
buildStrategies:
- $class: SkipInitialBuildOnFirstBranchIndexing
基本上默認不觸發,除了master和main這兩個命名例外。這是支持僅構建特定分支(兩個或更多)而不構建其余分支的方法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/420623.html
標籤:
