Understanding default parameter value in declarative pipeline

Hi, my declarative pipeline has several build parameters. I would like a parameter default value to be applied the first time the pipeline is run but, thereafter, the value entered by the user should become the default. Is that possible?

It seems strange that it is possible to set a parameter’s default value in the GUI Configure page, but the entered value gets overwritten by the script value the next time the job is run. How is this intended to work?

Hi,
I believe that is not supported “natively” by Jenkins

Yes you can!
You can set your jenkinsfile like this.

pipeline {
  parameters {
    choice(
      name: "key1",
      choices: params.key1 ? params.key1 : [""],
      description: "key1"
    )
    gitParameter(
      name: "branch",
      type: "PT_BRANCH",
      defaultValue: params.branch ? params.branch : "master",
      description: "branch",
      sortMode: "ASCENDING_SMART",
      selectedValue: "DEFAULT",
      useRepository: "git@172.16.0.17:test/.*git",
    )
  }
  ...
}

Hope this helps.