我有一个bash命令:
jenkins@jenkins:/home/ttt$ consul kv get --recurse new_project
new_project/persmetter:{"Project_ID":"persmetter", "Repository":"git@github.com:tt/persmetter.git", "Domain_name":"persmetter.com", "old_team":"2", "DB_pass":"dfdsfdsfds", "Project_public_ip":"16.99.215.245", "Project_private_ip":"10.133.99.35"}
new_project/persmetter12:{"Project_ID":"persmetter12", "Repository":"git@github.com:tt/persmetter12.git", "Domain_name":"persmetter12.com", "old_team":"2", "DB_pass":"sdfdsfsfsd", "Project_public_ip":"16.99.215.188", "Project_private_ip":"10.133.99.85"}
new_project/persmetter23:{"Project_ID":"persmetter23", "Repository":"git@github.com:tt/persmetter23.git", "Domain_name":"persmetter23.com", "old_team":"2", "DB_pass":"dsfdsfsdfsd", "Project_public_ip":"16.99.215.55", "Project_private_ip":"10.133.99.44"}
我想将此命令的stdout转换为数组,例如:
def dataArray = ["persmetter","persmetter12","persmetter23"]
然后使用此代码:
try {
List<String> artifacts = new ArrayList<String>()
def dataArray = ["persmetter","persmetter12","persmetter23"]
for(item in dataArray){
artifacts.add(item)
}
return artifacts
} catch (Exception e) {
print "There was a problem fetching the artifacts"
}
在Jenkins中创建一个下拉菜单。