Jenkins Active Choices 插件,从 yaml 文件动态填充复选框参数

Jenkins Active Choices Plugin, Dynamically fill checkbox parameters from yaml file

我是 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)

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

终于找到答案了,再次感谢@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]