英文:
Jenkinsfile set parameter dynamically
问题
抱歉,我无法提供代码的翻译。如果您有其他需要翻译的文本,请随时提出。
英文:
I would like to set the parameters default value dynamically that should be depended on condition. Is that possible?
pipeline {
agent any
parameters {
string(name: 'test', defaultValue: '', description: 'a string')
stages {
stage('Example') {
steps {
def type = "test"
if(type == "test") {
set defaultValue of parameter:test
}
}
}
}}}
答案1
得分: 0
一旦设置了“默认” Jenkins 作业参数(例如 string
),在运行时实际上无法更改它们(分配另一个值)。
但是,您可以使用一些其他插件,例如Active choice,它允许您设置更复杂的参数,并在其中使用条件、脚本和进一步的逻辑(包括您所要求的 - 一个参数的值基于另一个参数的值)- 请查看插件描述和示例。
有关如何在流水线中使用Active choices插件的一些示例的另一个有帮助的已回答的问题:https://stackoverflow.com/questions/43410204/active-choices-reactive-reference-parameter-in-jenkins-pipeline
英文:
Once the "default" Jenkins job parameters (e.g. string
) are set, you can't really change them (assign another value) during a runtime.
But you can use some other plugin(s), e.g. Active choice that allows you to set more complex parameters and use conditions, scripts and further logic with them (including what you're asking for - value of one is based on another parameter value) - see the plugin description and examples.
Another helpful and answered question with some examples regarding how to use Active choices plugin in pipeline: https://stackoverflow.com/questions/43410204/active-choices-reactive-reference-parameter-in-jenkins-pipeline
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论