微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 jenkins 的 groovy 脚本中获取远程分支

如何解决在 jenkins 的 groovy 脚本中获取远程分支

我正在尝试使用 Active choice 参数向 jenkins 添加一个参数,以便填充分支列表。我正在尝试使用以下代码用于 groovy 脚本来捕获远程分支。

def gettags = ("git ls-remote -t -h https://credentials@github.com/org/repo.git").execute()
return gettags.text.readLines().collect { 
  it.split()[1].replaceAll('refs/heads/','').replaceAll('refs/tags/','').replaceAll("\\^\\{\\}",'')
}

我也尝试过使用 ssh

def gettags = ("git ls-remote -t -h git@github.com:org/repo.git").execute()
return gettags.text.readLines().collect { 
  it.split()[1].replaceAll('refs/heads/','')
}

但是我无法获取远程分支。我假设我没有正确地传递凭据。我正在使用存储在 jenkins 中的凭据。

有人可以指导我吗。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。