Jenkinsfile with list of all parameter values or single value from parameter list

2.8k views Asked by At

I want to run jenkins job using jenkinsfile with list of all parameters value or with individual value from parameter list.

def deploy(env) {

step([$class: 'UCDeployPublisher',
siteName: siteName,
deploy: [
$class: 'com.urbancode.jenkins.plugins.ucdeploy.DeployHelper$DeployBlock',
deployApp: appName,
deployEnv: 'DEV',
deployVersions: "${compName}:${version}",
deployProc: simpleDeploy,
deployOnlyChanged: false,
deployReqProps: "ID=${params.ID}"
]]) 


CHOICES = [ 'id1', 'id2', 'id3', 'id4', 'id5' ]
PARAMETERS = CHOICES + "all"

 parameters {

    choice(
        name: 'ID',
        choices: PARAMETERS,
    )
    stage (DEV') {

        steps {
            script {
             if (params.ID == "all"){
                     CHOICES.each {
                     echo "$it"
                     }
                 deploy('devl') ===> this will call my deploy function
             }
             else {
                     echo "$params.ID"
                 deploy('devl') ===> this will call my deploy function
            }
         }
      }
    }

I was able to run job using bye selecting each value from droplist. But I also want to the run the job with all values from ID list. I tried with all but it is not taking all the the values 'id1', 'id2', 'id3', 'id4', 'id5'

1

There are 1 answers

5
apr_1985 On

You would need to define the choices in a var outside of the parameter and then use that as choices e.g.

CHOICES = [ 'id1', 'id2', 'id3', 'id4', 'id5' ]
PARAMETERS = CHOICES + "all"
pipeline {
    agent any
    parameters {
        choice(name: "ID", choices: PARAMETERS )
    }
    stages {
        stage('Test') {
          steps {
            script {
                if (params.ID == "all"){
                    CHOICES.each {
                        echo "$it"
                    }
                }
                else {
                    echo "$params.ID"
                }
            }
            
          }
        }
  }

}