Dzi*_*Jam 2 groovy jenkins jenkins-plugins jenkins-job-dsl jenkins-groovy
我有一个 JobDSL 脚本,它使用 Active Choice 参数插件提供的 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')
}
}
}
Run Code Online (Sandbox Code Playgroud)
使用configure块,我尝试覆盖节点<secureFallbackScript>及其<secureScript>下的值<sandbox>,但它不起作用。它会删除所有其他节点。我不太擅长 Groovy,所以我非常感谢任何帮助。<sandbox>将所有节点值覆盖为的正确方法是什么true?提前致谢。
以下是作业 XML 的链接供参考:https://gist.github.com/vzabawski/aae51eddd45a51978224e403cc505b5b
、activeChoiceParam和activeChoiceReactiveParam函数activeChoiceReactiveReferenceParam是静态 API 的一部分。Job DSL 作者介绍了动态 API。每当动态 API 可用于执行某些操作时,就不再支持负责相同逻辑的静态 API。
您应该阅读这些页面:
\n\n如何从静态 API 切换到动态 API 的示例:
\nactiveChoiceParam(\'Branch\') {\n description(\'Lists branches for integration job\')\n filterable()\n choiceType(\'SINGLE_SELECT\')\n groovyScript {\n script("return [\'The list of branches\']")\n fallbackScript("return [\'Unable to list branches\']")\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\xe2\x86\x93
\nchoiceParameter {\n name(\'Branch\')\n description(\'Lists branches for integration job\')\n filterable(true)\n choiceType(\'PT_SINGLE_SELECT\')\n script {\n groovyScript {\n script {\n script("return [\'The list of branches\']")\n sandbox(true)\n }\n fallbackScript {\n script("return [\'Unable to list branches\']")\n sandbox(true)\n }\n }\n }\n randomName(\'\')\n filterLength(0)\n}\nRun Code Online (Sandbox Code Playgroud)\n