如何在声明性管道中使用choice参数?

时间:2017-12-27 14:57:32

标签: jenkins-pipeline

我的例子:

pipeline {
  agent any
  parameters {
    choice(
        name: 'myParameter',
        choices: "Option1\Option2",
        description: 'interesting stuff' )
  }
}

输出错误:

"  unexpected char: '\'  " on the line with "choices" "

按照以下说明操作:https://github.com/jenkinsci/pipeline-model-definition-plugin/wiki/Parametrized-pipelines

关于我做错的任何想法或建议?

3 个答案:

答案 0 :(得分:7)

您需要使用\n代替\。 看到这段代码:

  pipeline {
  agent any
  parameters {
    choice(
        name: 'myParameter',
        choices: "Option1\nOption2",
        description: 'interesting stuff' )
  }
}

答案 1 :(得分:6)

pipeline {
  agent any
  parameters {
    choice(
      name: 'Env',
      choices: ['DEV', 'QA', 'UAT', 'PROD'],
      description: 'Passing the Environment'
    )
  }
  stages {
    stage('Environment') {
      steps {
        echo " The environment is ${params.Env}"
      }
    }
  }
}

答案 2 :(得分:3)

声明性詹金斯管道的文档说:

选择参数,例如:

pipeline { 
    .....
     parameters { choice(name: 'CHOICES', choices: ['one', 'two', 'three'], description: '') }

第一个是默认值