如何在詹金斯管道中创建动态复选框参数? [英] How to create dynamic checkbox parameter in Jenkins pipeline?

查看:157
本文介绍了如何在詹金斯管道中创建动态复选框参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 SO答案

    agent any
    stages {
        stage("Release scope") {
            steps {
                script {
                    // This list is going to come from a file, and is going to be big.
                    // for example purpose, I am creating a file with 3 items in it.
                    sh "echo \"first\nsecond\nthird\" > ${WORKSPACE}/list"

                    // Load the list into a variable
                    env.LIST = readFile (file: "${WORKSPACE}/list")

                    // Show the select input
                    env.RELEASE_SCOPE = input message: 'User input required', ok: 'Release!',
                            parameters: [choice(name: 'CHOOSE_RELEASE', choices: env.LIST, description: 'What are the choices?')]
                }
                echo "Release scope selected: ${env.RELEASE_SCOPE}"
            }
        }
    }
}

这使我们只能选择一个,因为它是一个choice参数,如何使用同一列表创建复选框参数,以便用户可以根据需要选择多个?例如:如果用户选择firstthird,则应显示最后一个回显 Release scope selected: first,third或以下命令也可以,所以我可以遍历并找到 true Release scope selected: {first: true, second: false, third: true}

This allows us to choose only one as it's a choice parameter, how to use the same list to create checkbox parameter, so the user can choose more than one as needed? e.g: if the user chooses first and third, then the last echo should print Release scope selected: first,third or the following is fine too, so I can iterate over and find the true ones Release scope selected: {first: true, second: false, third: true}

推荐答案

我可以如下使用extendedChoice

    agent any
    stages {
        stage("Release scope") {
            steps {
                script {
                    // This list is going to come from a file, and is going to be big.
                    // for example purpose, I am creating a file with 3 items in it.
                    sh "echo \"first\nsecond\nthird\" > ${WORKSPACE}/list"

                    // Load the list into a variable
                    env.LIST = readFile("${WORKSPACE}/list").replaceAll(~/\n/, ",")

                    env.RELEASE_SCOPE = input message: 'User input required', ok: 'Release!',
                            parameters: [extendedChoice(
                            name: 'ArchitecturesCh',
                            defaultValue: "${env.BUILD_ARCHS}",
                            multiSelectDelimiter: ',',
                            type: 'PT_CHECKBOX',
                            value: env.LIST
                      )]
                      // Show the select input
                      env.RELEASE_SCOPE = input message: 'User input required', ok: 'Release!',
                            parameters: [choice(name: 'CHOOSE_RELEASE', choices: env.LIST, description: 'What are the choices?')]
                }
                echo "Release scope selected: ${env.RELEASE_SCOPE}"
            }
        }
    }
}

这篇关于如何在詹金斯管道中创建动态复选框参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆