如何解决如何通过 Job DSL
我有一个 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>
和 <sandbox>
的值,但它不起作用。它会擦除所有其他节点。我不太擅长 Groovy,所以我真的很感激任何帮助。
将所有 <sandbox>
节点值覆盖为 true
的正确方法是什么?提前致谢。
以下是职位 XML 的链接以供参考:https://gist.github.com/vzabawski/aae51eddd45a51978224e403cc505b5b
解决方法
activeChoiceParam
、activeChoiceReactiveParam
和 activeChoiceReactiveReferenceParam
函数是静态 API 的一部分。 Job DSL 作者引入了 dynamic API。每当可以使用动态 API 做某事时,就不再支持负责相同逻辑的静态 API。
您应该阅读这些页面:
如何从静态 API 切换到动态 API 的示例:
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']")
}
}
↓
choiceParameter {
name('Branch')
description('Lists branches for integration job')
filterable(true)
choiceType('SINGLE_SELECT')
script {
groovyScript {
script {
script("return ['The list of branches']")
sandbox(true)
}
fallbackScript {
script("return ['Unable to list branches']")
sandbox(true)
}
}
}
randomName('')
filterLength(0)
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。