我正在尝试获取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 。
答案 0 :(得分:0)
以下代码对我有用:
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')