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

前端 未结 6 1804
暖寄归人
暖寄归人 2021-02-02 09:01

The Extended Choice Parameter plugin is great and I use it in jobs configured via the UI https://wiki.jenkins-ci.org/display/JENKINS/Extended+Choice+Parameter+plugin

How

6条回答
  •  执笔经年
    2021-02-02 09:53

    Works for me :

    I needed to retrieve all the versions number of artifacts from a Nexus Repo:

     properties ([
        parameters([
            choice(choices: ['PROD', 'DEV', 'QA'], description: '', name: 'ParamEnv' ),   
            string(name: 'ParamVersion', defaultValue: '', description: 'Version to deploy'),
            extendedChoice(
                name: 'someName',
                description: '',
                visibleItemCount: 50,
                multiSelectDelimiter: ',',
                type: 'PT_SINGLE_SELECT',
                groovyScript: '''
                import groovy.json.JsonSlurper
                    List nexusPkgV = new ArrayList()        
                    def pkgObject = ["curl", "https://xxxx:xxxx@xxxxxxxxxx"].execute().text
                    def jsonSlurper = new JsonSlurper()
                    def artifactsJsonObject = jsonSlurper.parseText(pkgObject)
                    def dataA = artifactsJsonObject.items
                    for (i in dataA) {
                        nexusPkgV.add(i.version)
                    }
                return nexusPkgV
                '''
            )
        ])
    ]) 
    

提交回复
热议问题