【问题标题】:Jenkins Active Choices Plugin, Dynamically fill checkbox parameters from yaml fileJenkins Active Choices Plugin,从 yaml 文件中动态填充复选框参数
【发布时间】:2021-10-20 00:23:16
【问题描述】:

我是 Jenkins 的新手,每天都在探索不同的插件和文章,以了解有关 Jenkins 的新知识。

我发现,可以使用上传到Jenkins服务器的json文件中的主动选择参数插件在构建之前填充参数。我用谷歌搜索了它,但找不到正确的解释。我得到的提示是在 Active Choice 参数中使用了 Groovy 脚本。如果可能,请告诉我。

感谢 @Noam Helmer 的参考,但我如何从下面的文件中捕获 group1、group2、group3、group4...。 all、children、hosts 无论有多少组添加到这个文件中,它都将保持不变。

all:
  children:
    group1:
      hosts:
        xyz4.axs: 
    group2:
      hosts:
        xyz5.adf: 
        xyz8.asf: 
    group3:
      hosts:
        xyz3.asd: 
        xyz6.ads: 
        xyz7.asd: 

我尝试了以下脚本,但无法获取组名。

import org.yaml.snakeyaml.Yaml
List groups = []
Yaml parser = new Yaml()
def example = parser.load(("/var/lib/jenkins/workspace/groups/hosts" as File).text)
for (details in example){
  groups.add(details)
}
println(groups)

现在,我不知道我是否走在正确的轨道上,请给我一个提示。 任何提前帮助将不胜感激。

【问题讨论】:

标签: jenkins groovy yaml jenkins-plugins jenkins-groovy


【解决方案1】:

终于找到答案了,再次感谢@NoamHelmer的回复。

import org.yaml.snakeyaml.Yaml
List groups = []
Yaml parser = new Yaml()
def example = parser.load(("path to file" as File).text)

for(anf in example.keySet()){
    groups.add(anf)
} 
        
for(inf in example.all.children.keySet()){
    groups.add(inf)  
}

return(groups)

输出将是:[all, group1, group2, group3]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多