【发布时间】:2020-03-08 09:18:16
【问题描述】:
我有一份詹金斯的工作:
properties([
parameters([
[$class: 'ChoiceParameter', choiceType: 'PT_CHECKBOX', description: '''The name of the image to be used.''', filterLength: 1, filterable: true, name: 'OS', randomName: 'choice-parameter-15413073438404172', script: [$class: 'GroovyScript', fallbackScript: [classpath: [], sandbox: true, script: ''], script: [classpath: [], sandbox: true, script: '''templates = [
"BB-Win7-x32-SP1",
"BB-Win7-x64-SP1",
"BB-Win10-x64-RS1",
"BB-Win10-x64-RS2",
"BB-Win10-x32-RS5"]
return templates''']]]])
])
....
....
这是按预期工作并为 GUI 生成复选框属性。
现在,我想根据工作空间中的文件动态生成这些选项。为此,我需要 groovy 脚本中的 workspace 环境变量。我该怎么做?
【问题讨论】:
-
要运行你的 groovy 脚本(从 Git 检出工作区后需要读取工作区中文件的脚本...)Jenkins 需要创建参数。为了创建参数,它需要运行一个 groovy 脚本。你在这里遇到了一些先有鸡还是先有蛋的问题。你看过 ActiveChoice 插件吗?
-
我所说的 groovy 脚本并不是实际的管道。这是
ChoiceParameter类中的脚本。 -
这就是 ActiveChoice 可以实现的。
标签: jenkins jenkins-pipeline jenkins-groovy