[英]How to access the BRANCH_NAME variable within a Jenkins pipeline running on Windows?
[英]Possible to extract part of $BRANCH_NAME string in Jenkins Pipeline?
我目前正在構建一個多分支管道。 我正在嘗試構建一個 docker 圖像並使用始終為“feature/XXX-111”的分支名稱對其進行標記。 但是,當我使用 $branch_name env 變量獲取分支名稱時,使用 tag -t 命令構建的 docker 不像“feature/XXX-111”分支名稱中的“/”。 所以我想知道是否可以只獲取分支名稱的“XXX-111”部分並刪除“feature/”。 任何幫助將不勝感激。
謝謝!
這有效:
def branch_name = 'feature/XXX-111'
def regex_to_search = 'feature/([\\w-_]*)'
def matcher = branch_name =~ regex_to_search
if (matcher.find()) {
println matcher.group(1)
}
Output:
XXX-111
您可以使用 groovy 拆分 function -
def branchName = 'feature/XXX-111'
def newBranchName = branchName.split('/')[1]
println(newBranchName)
Output:
XXX-111
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.