0

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
          }
        }
    }
}}}
marcus.w
  • 19
  • 2

1 Answers1

0

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: Active Choices Reactive Reference Parameter in jenkins pipeline

David-kn
  • 323
  • 2
  • 8