jenkinsfile动态选择参数配置

配置代码

properties([
    parameters(
        [
            [
                $class: 'CascadeChoiceParameter', 
                choiceType: 'PT_SINGLE_SELECT', 
                description: '回滚版本', 
                filterLength: 1, 
                filterable: true, 
                name: 'rollback_ver', 
                randomName: 'choice-parameter-69483048065305', 
                referencedParameters: 'deploy_op', 
                script: [
                    $class: 'GroovyScript', 
                    fallbackScript: [
                    classpath: [], 
                    sandbox: false, 
                    script: ''
                    ], 
                    script: [
                        classpath: [], 
                        sandbox: false, 
                        script: '''if (deploy_op.equals("deploy")) {
                                return [
                                    "--"
                                ];
                            } else if (deploy_op.equals("rollback")) {
                                ref=["/bin/bash", "-c", "ls /var/jenkins_home/workspace/app/release"].execute().text.readLines();
                                return ref;
                            } else {
                                return ["Unknown action"];
                            }'''
                    ]
                ]
            ],
            choice(name: 'deploy_op', choices: 'deploy\nrollback', description: 'deploy部署,rollback回滚')
        ]
    )
])

pipeline {
 ...
 ...
}

主要意义: 选择deploy_op选项的具体值,动态改变rollback_ver的内容选项,rollback_ver的选项值通过ls /var/jenkins_home/workspace/app/release列出目录下打包的历史版本文件名得到