jenkins-pipeline - 使用 Groovy 脚本的 Jenkins Active Choice 参数调用函数

标签 jenkins-pipeline jenkins-groovy

尝试在事件选择参数“脚本”部分调用定义的函数似乎不起作用:

def JustTest() {
  xxx = ['a','b']
  return xxx
}

properties([
    parameters([
        [$class: 'ChoiceParameter', 
            choiceType: 'PT_SINGLE_SELECT', 
            ////
            some code omitted
            ////
            script: [
                classpath: [], sandbox: false, 
                script:
                """
                def mymy = JustTest()
                return mymy
                """
                ]
            ]
        ]
    ])
])

pipeline {
  some code
}

尝试使用参数构建时收到错误

附注'input' 不适合我,我需要在开始之前选择参数

最佳答案

在没有看到错误的情况下,我认为这只是确保您向 choices 参数提供正确数据类型(字符串)的问题。

对于 List 的返回类型,将它们与换行符连接在一起,如下所示。如果是其他东西,您将需要进一步操作它

    List JustTest() {
         List xxx = ['a','b']
         return xxx
    }

    properties([
        parameters([
            choice(name: 'PARAM', choices: JustTest().join('\n'), description: 'Choice'),
        ])
    ])

我认为不需要如此冗长的选择实现,但也许我们的 jenkins 插件存在差异。或许可以试试我的较短的那个,而不用 $class 冗长。

关于jenkins-pipeline - 使用 Groovy 脚本的 Jenkins Active Choice 参数调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56998355/

相关文章:

git - Jenkins groovy - 如何从最新提交中检索标签?

jenkins - 有没有办法在 Jenkins 中获取 Gitlab 管道工件?

java - 无法使用 File 或 nio 检查 Pipeline、NonCPS 或共享库中文件是否存在

linux - 如何防止docker在错误时停止/删除容器

jenkins - 如何识别 Jenkins pipeline 的 groovy 脚本中的编译错误?

java - 错误java.lang.NoSuchMethodError : No such DSL method '***' found among steps

Jenkinsfile - 不要加载隐式全局库

jenkins - 运行时为从代理上运行的每个 jenkins 作业创建 pv/pvc

jenkins - 列出脚本化的Jenkins Pipeline中正在使用的插件

intellij-idea - IntelliJ GSDL : Define method with optional arguments