Thursday, June 15, 2023

Jenkins Active Choice Parameter - PT_SINGLE_SELECT

 In Jenkins Active Choice Parameter, PT_SINGLE_SELECT is the simplest form where it returns the values in list. In UI it appears as a dropdown.


Example:

        parameters([

            [$class: 'ChoiceParameter', 

                choiceType: 'PT_SINGLE_SELECT', 

                description: 'Select the Environment to Run', 

                filterLength: 1, 

                filterable: false, 

                name: 'RunEnv', 

                script: [

                    $class: 'GroovyScript', 

                    fallbackScript: [

                        classpath: [], 

                        sandbox: true, 

                        script: 

                              "return['Could not get The environemnts']"

                    ], 

                    script: [

                        classpath: [], 

                        sandbox: true, 

                        script:

                              "return['NONE','prod1', 'prod2', 'prod3', 'prod4', 'prod5', 'prod6', 'prod7']"

                            

                    ]

                ]

            ]

)]


Above code is what I use in Declarative Jenkins Pipeline. You can just copy paste the code in a file and it should work fine. You don't need the pipeline{} code. 


Pipeline{} code will come under above code. Bit weird but works.

Also, you need approve the above. code in Jenkins -> Manage Jenkins -> In Process Script Approval.


If the Jenkins is managed by external team, then only way is to request them to approve. 

No comments:

Post a Comment