詹金斯管道 - 如何动态给出选择参数 [英] Jenkins pipeline - How to give choice parameters dynamically

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

问题描述

pipeline {
  agent any
  stages {
    stage("foo") {
        steps {
            script {
                env.RELEASE_SCOPE = input message: 'User input required', ok: 'Release!',
                        parameters: [choice(name: 'RELEASE_SCOPE', choices: 'patch
minor
major', 
                                     description: 'What is the release scope?')]
            }
            echo "${env.RELEASE_SCOPE}"
        }
    }
  }
}

在上面的代码中,选择是硬编码的(补丁 minor major)——我的要求是在下拉列表中动态给出选择值.我从调用 api 获取值 - Artifacts list (.zip) file names from artifactory在上面的例子中,当我们构建时它请求输入,但我想做一个带参数构建"

In this above code, The choice are hardcoded (patch minor major) -- My requirement is to dynamically give choice values in the dropdown. I get the values from calling api - Artifacts list (.zip) file names from artifactory In the above example, It request input when we do the build, But i want to do a "Build with parameters"

请就此提出建议/帮助.

Please suggest/help on this.

推荐答案

取决于你如何从 API 获取数据,会有不同的选项,例如让我们假设你以字符串列表的形式获取数据(我们称之为 releaseScope),在这种情况下,您的代码如下:

Depends how you get data from API there will be different options for it, for example let's imagine that you get data as a List of Strings (let's call it releaseScope), in that case your code be following:

...
script {
    def releaseScopeChoices = ''
    releaseScope.each {
        releaseScopeChoices += it + '
'
    }

    parameters: [choice(name: 'RELEASE_SCOPE', choices: ${releaseScopeChoices}, description: 'What is the release scope?')]
}
...


希望对您有所帮助.


hope it will help.

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

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