如何通过 activeChoiceReactiveParam 将引用参数发送到 readFileFromWorkspace

发布于 2025-01-14 12:33:27 字数 1746 浏览 3 评论 0原文

我正在尝试将引用参数(“产品”)发送到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光匆匆的小流年 2025-01-21 12:33:27

嗯,看起来上面的代码很完美,唯一的问题是 services.groovy 脚本的位置。

我将该文件从 DSL 目录中取出(因为我不希望它被解析为 DSL 文件),将其引用到正确的位置,并且它工作得很好。

更新的管道:

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('services.groovy'))
                fallbackScript('return ["ERROR"]')
            }
            referencedParameter("product")
        }
    }
}

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:

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('services.groovy'))
                fallbackScript('return ["ERROR"]')
            }
            referencedParameter("product")
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文