簡體   English   中英

Jenkins管道腳本-更改git分支

[英]Jenkins pipeline script - change git branch

我正在嘗試獲取git分支的名稱,但是以下代碼未返回預期的輸出。

def getbranches = ("git ls-remote -h https://github.com/my_repo").execute().getText()

print getbranches.readLines()
.collect { it.split()[1].replaceAll("refs/heads/", "")  }
.unique()
.findAll { it.startsWith('r') }

它應該返回類似: release / 1.1的信息,但輸出false

以下代碼為我工作:

git url: 'https://github.com/my_repo', branch: 'master'

def getBranch = bat (returnStdout : true, script: "\"C:\\Program Files\\Git\\bin\\sh.exe\" --login -c \"git branch -a | grep remotes/origin/release/[^/]*\$ | cut -d / -f 4\"")
String[] getReleaseVersion = getBranch.split('\n')

暫無
暫無

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

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