在 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 (将#修改为@)