You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

参数化Jenkins流水线:单选择项未显示问题咨询

解决Jenkins ChoiceParameter下拉框为空的问题

我之前踩过一模一样的坑!你的配置里差了个关键细节——Jenkins的ChoiceParameter对choices参数的格式要求不是Groovy数组,而是换行分隔的字符串,所以你传数组的时候Jenkins识别不出来,自然下拉框就空了。

修正后的配置代码

把你的choices部分改成换行分隔的字符串就行,有两种易读的写法:

写法1:用转义换行符

properties( [ 
    parameters([ 
        [ 
            $class: 'ChoiceParameter', 
            choiceType: 'PT_SINGLE_SELECT', 
            description: 'Select your testcase', 
            filterable: false, 
            name: 'testCases', 
            choices: 'HappyFlow\nNewYork_HappyFlow' 
        ] 
    ]), 
    pipelineTriggers([]) 
] )

写法2:用Groovy多行字符串(推荐,更直观)

properties( [ 
    parameters([ 
        [ 
            $class: 'ChoiceParameter', 
            choiceType: 'PT_SINGLE_SELECT', 
            description: 'Select your testcase', 
            filterable: false, 
            name: 'testCases', 
            choices: '''HappyFlow
NewYork_HappyFlow''' 
        ] 
    ]), 
    pipelineTriggers([]) 
] )

额外小提示

如果你用的是Declarative Pipeline,写法会更简洁,直接用choice指令就支持数组格式了:

pipeline {
    agent any
    parameters {
        choice(
            name: 'testCases',
            choices: ['HappyFlow', 'NewYork_HappyFlow'],
            description: 'Select your testcase'
        )
    }
    stages {
        stage('Test') {
            steps {
                echo "Running test case: ${params.testCases}"
            }
        }
    }
}

改完之后重新保存流水线,再去触发的时候下拉框就能看到预设的选项啦!

内容的提问来源于stack exchange,提问作者Ceesiebird

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 10:03:07