Jenkins Declarative Pipeline with extended choice parameter

不想你离开。 提交于 2019-12-21 05:08:09

问题


I tried out to implement my first Declarative Pipeline with Jenkins to be able to put also the parameter definitions of a job under SCM.

I wanted to transfer an existing job that has an extended choice paraemter. Unfortunately I was not able to add it to the parameters{...} section of my script.

On the plugin page: https://wiki.jenkins-ci.org/display/JENKINS/Extended+Choice+Parameter+plugin I found a comment that stated it should be possible by:

import com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition

def type = "PT_JSON"
def groovyScript  = null
def propertyValue  = null
def projectName = null
def propertyFile = null
def groovyScriptFile = "/path_to/script.groovy"
... 
def extendedChoice = new ExtendedChoiceParameterDefinition(name,
            type,
            propertyValue,
            projectName,
            propertyFile,
            groovyScript,
.....

input message: 'Param1', parameters: [extendedChoice]

Unfortunately this was not working for me. "input Requested" gave a non specified error. While I could live with an "input message" solution, it was not what I was looking for in the first place. I want to add this parameter to the parameter section as mentioned already. But I am not able to find any place where this is described. Any suggestions how to go on, or maybe also alternative approaches/plugins?


回答1:


You should go to your http://jenkins-url.com/pipeline-syntax on the Sample step dropdown select properties There is a checkbox for This project is parameterized then you can select Add parameter Extended Choice Parameter and you can generate the groovy for that for your pipeline.




回答2:


This is what i used and Tested sucessfully for Single parameter you might need to convert it for Json

com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition extch =new com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition( "NAME", "PT_SINGLE_SELECT", "VALUE, a, b", null, null, null, null, null,null, null,null,null, null, null, null,null, null, null,null, null, null, null, null, null, null,null,false,false,2,"DESC", "," )


来源:https://stackoverflow.com/questions/44518963/jenkins-declarative-pipeline-with-extended-choice-parameter

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