Jenkins Choice parameter Passing to a pipeline Job

前端 未结 5 500
粉色の甜心
粉色の甜心 2020-12-30 03:00

Currently I have a pipeline job which has different paramters where one of this parameters is a Choice parameter. Here is the config.xml output of that job parameter:

<
5条回答
  •  心在旅途
    2020-12-30 03:31

    As documented at https://www.jenkins.io/doc/book/pipeline/syntax/#parameters in September 2020, the documented syntax to use a choice parameter in a pipeline is:

    pipeline {
        agent any
        parameters {
            choice(
                name: 'CHOICE',
                choices: ['one', 'two', 'three'],
                description: ''
            )
        }
        stages {
            stage('Example') {
                steps {
                    echo "Choice: ${params.CHOICE}"
                    sh "echo Choice: ${params.CHOICE}"
                    sh 'echo Choice: $CHOICE'
                }
            }
        }
    }
    

    In testing, the choice defaults to the first parameter in the list, I have not looked into if this has potential to be otherwise.

    All three versions of the task perform the same. Note the specific quotes used.

提交回复
热议问题