Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do pipeline parameters and jenkins GUI parameters work together?

I am using a pipeline in a jenkinsfile and I am not sure how to properly link the job in Jenkins and the pipeline.

I defined parameters in my jenkinsfile (some with default values, some without) and have them initialized from the parameters coming from jenkins gui. The problem is that it seams the parameters in my pipeline are overiding my job parameters, EVEN when no default value is specified in the pipeline which means the pipeline is overriding my job setup in jenkins.

for example, one of my job is setup to run the pipeline with some specific values (all NON-EMPTY), if I trigger the job, the pipeline seem to reset the properties to '' for fields b and c.

How to I get the pipeline to not touch my jenkins job definition?

e.g. the params in the pipeline:

    properties([
      parameters([
        string(name: 'a',   defaultValue: 'Default A value', description: '', ),
        string(name: 'b',   description: '', ),
        string(name: 'c',   description: '', ),
       ])
])

I am not find any help in the documentation at https://jenkins.io/doc/book/pipeline/syntax/#parameters-example

like image 397
NicolasW Avatar asked Jun 08 '17 14:06

NicolasW


People also ask

How does Jenkins pipeline pass Choice parameters?

Go to Jenkins Home, select New Item, add a name for your Job, for the project type, select Pipeline project and click on Ok. On the configure job page select the This project is parameterized checkbox in the general tab. Now, we will add an Active Choices Parameter which renders our Application Tiers as a Dropdown.

What is parameterized pipeline in Jenkins?

A parameterized pipeline allows us to set needed parameters dynamically at build time.

How are parameters defined in scripted pipeline?

Configuring parameters with Scripted Pipeline is done with the properties step, which can be found in the Snippet Generator. If you configured your pipeline to accept parameters using the Build with Parameters option, those parameters are accessible as members of the params variable.


1 Answers

Ah, yes, it got me the first time around also.

The first time that you run the pipeline, the jenkinsFile DSL job definition pretty much overrides the whole job definition that you have entered thru the GUI. That affects the parameters in particular.

So make sure you define the parameters exactly how you want them in the Jenkinsfile, then run the job once, and the GUI will have the same config for the parameters, so that when you run again, it will ask for the parameters and use the default values, that you specified in the DSL. There is nothing more to it.

Yes, having to run twice everytime you modify the parameters in the DSL is annoying. But it sort of makes sense if you consider that the job has to execute for the DSL to be evaluated, but first it needs to ask for parameters if you have some defined via the UI, BEFORE it checks out and evaluates the DSL...

like image 200
Patrice M. Avatar answered Nov 02 '22 10:11

Patrice M.