如何通过 activeChoiceReactiveParam 将引用参数发送到 readFileFromWorkspace
我正在尝试将引用参数(“产品”)发送到 Groovy 脚本(services.groovy),该脚本由使用 activeChoiceReactiveParam 包装的命令 readFileFromWorkspace 触发。
预期结果:获取包含文件内容的下拉列表。
实际结果:处理 DSL 脚本时作业失败
ERROR: (services.groovy, line 5) No such property: product for class: dsl.jobs.argocd.services
我尝试将产品引用参数定义为环境变量(并在 services.groovy 脚本中更新),但它不起作用。
我尝试在目录 /tmp/ 中重新创建 services.groovy 文件,但在查找文件时遇到问题。
products.groovy:
package dsl.jobs.argocd
return ['a','b','c']
services.groovy:
package dsl.jobs.argocd
return_value = []
if (product.equals("a")){
return_value = ['e']
}
if (product.equals("b")){
return_value = ['f']
}
if (product.equals("c")){
return_value = ['g']
}
return return_value;
管道:
pipelineJob("test") {
description("test")
keepDependencies(false)
parameters {
activeChoiceParam('product') {
description('What product would you like to update?')
filterable()
choiceType('SINGLE_SELECT')
groovyScript {
script(readFileFromWorkspace('dsl/jobs/argocd/products.groovy'))
fallbackScript('return ["ERROR"]')
}
}
activeChoiceReactiveParam('service') {
description('Which services would you like to update?')
filterable()
choiceType('CHECKBOX')
groovyScript {
script(readFileFromWorkspace('dsl/jobs/argocd/services.groovy'))
fallbackScript('return ["ERROR"]')
}
referencedParameter("product")
}
}
}
我处理这个错误吗?有没有不同的方法在几个 Groovy 文件中使用相同的参数?
I'm trying to send a referencedParameter ('product') to a Groovy script (services.groovy) that is triggered by the command readFileFromWorkspace that is wrapped with an activeChoiceReactiveParam.
Expected result: Get a dropdown list with the files content.
Actual result: The job fails when processing the DSL script
ERROR: (services.groovy, line 5) No such property: product for class: dsl.jobs.argocd.services
I tried to define the products referenced parameter as an environment variable (And updated in the services.groovy script), it didn't work.
I tried to re-create the services.groovy file in the directory /tmp/ but I had issues finding the files.
products.groovy:
package dsl.jobs.argocd
return ['a','b','c']
services.groovy:
package dsl.jobs.argocd
return_value = []
if (product.equals("a")){
return_value = ['e']
}
if (product.equals("b")){
return_value = ['f']
}
if (product.equals("c")){
return_value = ['g']
}
return return_value;
Pipeline:
pipelineJob("test") {
description("test")
keepDependencies(false)
parameters {
activeChoiceParam('product') {
description('What product would you like to update?')
filterable()
choiceType('SINGLE_SELECT')
groovyScript {
script(readFileFromWorkspace('dsl/jobs/argocd/products.groovy'))
fallbackScript('return ["ERROR"]')
}
}
activeChoiceReactiveParam('service') {
description('Which services would you like to update?')
filterable()
choiceType('CHECKBOX')
groovyScript {
script(readFileFromWorkspace('dsl/jobs/argocd/services.groovy'))
fallbackScript('return ["ERROR"]')
}
referencedParameter("product")
}
}
}
Am I approaching this wrong? Is there a different way to use the same parameter in a few Groovy files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,看起来上面的代码很完美,唯一的问题是 services.groovy 脚本的位置。
我将该文件从 DSL 目录中取出(因为我不希望它被解析为 DSL 文件),将其引用到正确的位置,并且它工作得很好。
更新的管道:
Well, seems the code above is perfect, the only problem was the location of the services.groovy script.
I took the file out of the DSL directory (Since I don't want it to be parsed as a DSL file), referenced it to the correct location, and it works perfect.
Updated pipeline: