问题描述
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\nminor\nmajor',
description: 'What is the release scope?')]
}
echo "${env.RELEASE_SCOPE}"
}
}
}
}
在上面的代码中,选项是硬编码的(补丁\ nminor \ nmajor)-我的要求是在下拉列表中动态给出选择值.我从调用api得到的值-来自工件的工件列表(.zip)文件名在上面的示例中,当我们进行构建时,它会请求输入,但是我想执行使用参数进行构建"
In this above code, The choice are hardcoded (patch\nminor\nmajor) -- My requirement is to dynamically give choice values in the dropdown.I get the values from calling api - Artifacts list (.zip) file names from artifactoryIn 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 + '\n'
}
parameters: [choice(name: 'RELEASE_SCOPE', choices: ${releaseScopeChoices}, description: 'What is the release scope?')]
}
...
希望对您有所帮助.
hope it will help.
这篇关于Jenkins管道-如何动态给定选择参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!