【发布时间】:2021-10-04 22:37:30
【问题描述】:
我有一个 JobDSL 脚本,它使用 Active Choice Parameters 插件提供的 Active Choice 参数创建 Jenkins 管道作业。不幸的是,JobDSL 不支持在沙箱中运行 Active Choice Groovy 脚本的参数(在 UI 中可用),所以我试图通过配置块启用它。
这是我的 JobDSL 脚本:
pipelineJob("my-pipeline") {
logRotator(-1, 10)
parameters {
activeChoiceParam('Branch') {
description('Lists branches for integration job')
filterable()
choiceType('SINGLE_SELECT')
groovyScript {
script("return ['The list of branches']")
fallbackScript("return ['Unable to list branches']")
}
}
activeChoiceReactiveParam('Build') {
description('Specifies which build from selected branch will be used for deployment. Only builds that contain Terraform plan are listed.')
choiceType('SINGLE_SELECT')
groovyScript {
script("return ['Selected build']")
fallbackScript("return ['Unable to list builds']")
}
referencedParameter('Branch')
}
activeChoiceReactiveReferenceParam('Artifacts') {
description('Lists artifacts from build specified')
choiceType('FORMATTED_HTML')
groovyScript {
script(scriptGen("return ['Job artifacts']")
fallbackScript("return ['Unable to list artifacts']")
}
referencedParameter('Branch')
referencedParameter('Build')
}
}
definition {
cpsScm {
scm {
git {
remote {
github('mainorg/my-repo', 'https', 'github.com')
credentials('my-creds')
}
branch('*/master')
}
}
scriptPath("ci/Jenkinsfile")
lightweight(true)
}
}
configure {
it / 'properties' / 'hudson.model.ParametersDefinitionPropert' / 'parameterDefinitions' / 'org.biouno.unochoice.ChoiceParameter' / 'script' / 'secureScript' {
'sandbox'('true')
}
}
}
使用configure 块,我试图覆盖<secureFallbackScript> 和<secureScript> under<sandbox> 节点的值,但它不起作用。它会擦除所有其他节点。我不太擅长 Groovy,所以我非常感谢任何帮助。
将所有<sandbox> 节点值覆盖为true 的正确方法是什么?提前致谢。
这里是作业 XML 的链接以供参考:https://gist.github.com/vzabawski/aae51eddd45a51978224e403cc505b5b
【问题讨论】:
标签: jenkins groovy jenkins-plugins jenkins-groovy jenkins-job-dsl