bash - 使用 Groovy 脚本列出具有活动选择的分支
问题描述
我正在尝试使用主动选择插件列出参数化 Jenkins 作业的 github 分支。我尝试了以下 groovy 脚本,但无济于事 - 下拉列表中未检索/列出任何分支。
1.
def process = ("ssh-agent bash -c 'ssh-add /home/ubuntu/.ssh/id_rsa; git ls-remote -t -h git@github.com:username/repository.git'").execute()
return process.text.readLines().collect {
it.split()[1].replaceAll('refs/heads/', '').replaceAll('refs/tags/', '').replaceAll("\\^\\{\\}", '')
}
2.
def command = 'ssh-add /home/ubuntu/.ssh/id_rsa; git ls-remote -t -h git@github.com:username/repository.git'
def process = ["ssh-agent", "bash", "-c", command].execute()
return process.text.readLines().collect {
it.split()[1].replaceAll('refs/heads/', '').replaceAll('refs/tags/', '').replaceAll("\\^\\{\\}", '')
}
3.
def process = ["ssh-agent", "bash", "-c", "ssh-add", "/home/ubuntu/.ssh/id_rsa", "git", "ls-remote", "-t", "-h", "git@github.com:username/repository.git"].execute()
return process.text.readLines().collect {
it.split()[1].replaceAll('refs/heads/', '').replaceAll('refs/tags/', '').replaceAll("\\^\\{\\}", '')
}
我怀疑这与 groovy 如何解析嵌套的 shell 命令有关,但我不确定。
您的帮助将不胜感激。
更新
我按照@cfrick 的建议在 groovysh 中尝试了脚本 2,它工作得非常好。似乎这个问题与我的 Jenkins 版本有关,因为可扩展选择参数插件与我的 groovy 脚本有同样的问题。
我决定解决我的需要,并放弃了这整件事。
解决方案
推荐阅读
- php - Authorize.Net AIM 响应中缺少 HMAC-SHA512 哈希
- python - 为什么 JupyterLab 给出的输出与 shell 不同?
- python - Python:忽略文本文件的注释,该文本文件被解析为字典以写入 CSV
- javascript - 如何使用 dc.js 在饼图中心显示值
- python - 努力在python脚本中传递ansible变量
- c# - 如何将 DataContract / DataMember 注释用于特定服务而不是所有服务
- php - 导出到excel文件时如何设置粗体行。?
- excel - 循环遍历第一行和列并将值粘贴到另一个使用 VBA 的工作表
- reactjs - 反应 - 在函数 setstate 内不更新状态
- python - time.asctime() V/S time.asctime(time.localtime())