'How to prevent parameters created with Scripted Pipeline to replace the ones set on the UI?

With Jenkins Declarative Pipeline syntax, in the parameters block, the behavior of the parameters is like so:

  1. If the defaultValue of the parameter is customized in the Jenkins UI, it will take precedence over the defaultValue in the Jenkinsfile.
  2. It will not remove the parameters which are not defined in code but are set in the UI.

However, if I set any parameters using properties in a scripted pipeline, the defaultValue set in the UI gets replaced (1) and parameters not set gets deleted (2).



Solution 1:[1]

I managed to work around this by editing xml definitions, it turns out that there is parameter declaration under <actions> too and removing parameters there fixed this for me. That is the parameters are still under <properties> tag but not under <actions> anymore and it works.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1