How can I use the Extended Choice Parameter plugin in a Jenkins pipeline script?

流过昼夜 提交于 2019-12-03 02:34:20

Since April's 2nd, 2019 it's now possible because of this commit: https://github.com/jenkinsci/extended-choice-parameter-plugin/pull/25

You can use it like this for instance:

properties([
    parameters([
        extendedChoice( 
            name: 'PROJECT', 
            defaultValue: '', 
            description: 'Sélectionnez le projet à construire.', 
            type: 'PT_SINGLE_SELECT', 
            groovyScript: valueKeysScript,
            descriptionGroovyScript: valueNamesScript
        )
    ])
])

If you want to know every possible parameter you have to refer to the source code. If you want to know every possible value for the "type" key, have a look at the PT_* constants.

Here is my workaround for this pb:

https://gist.github.com/jgraglia/44a7443847cff6f0d87387a46c7bb82f

ie : manually instanciate the parameter by declaring all the args

I was able to add a multi checklist parameter to my pipeline with that.

Like mkobit said it is currently not possible to use the extended choice plugin as a build parameter.

What I like to use as a workaround is a construct like the following

timeout(time: 5, unit: TimeUnit.MINUTES) {
    def result = input(message: 'Set some values', parameters: [
        booleanParam(defaultValue: true, description: '', name: 'SomeBoolean'),
        choice(choices: "Choice One\nChoice Two", description: '', name: 'SomeChoice'),
        stringParam(defaultValue: "Text", description: '', name: 'SomeText')
    ]) as Map<String, String>
}

echo "${result.SomeBoolean}, ${result.SomeChoice}, ${result.SomeText}"

And call it in the beginning of my pipeline. You then get asked for these inputs shortly after your build starts.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!