简体   繁体   English

Jenkins管道脚本-更改git分支

[英]Jenkins pipeline script - change git branch

I'm trying to get the name of a git branch, but the following code doesn't return the expected output. 我正在尝试获取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') }

It should return something like: release/1.1 but it outputs false . 它应该返回类似: release / 1.1的信息,但输出false

The following code worked for me: 以下代码为我工作:

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