Jenkinsfile 动态设置参数

huangapple go评论103阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年1月9日 17:07:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75055075.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定