Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make sure list of parameters are updated before running a Jenkins pipeline?

A Jenkins pipeline project is configured to fetch its Jenkinsfile from a Git repo:

Pipeline Def

If I change the list of parameters, for example, from:

properties([         parameters([                 string(name: 'FOO', description: 'Choose foo')         ]) ]) 

to:

properties([         parameters([                 string(name: 'FOO', description: 'Choose foo'),                 string(name: 'BAR', description: 'Choose bar')         ]) ]) 

And run the build, the first run does not show the newly added BAR parameter:

Parameter list not updated

As the updated Jenkins file expects the BAR parameter to be present, this causes the first build after the change to fail as the user is not presented with an input to enter this value.

Is there a way to prevent this? To make sure the Jenkinsfile is up-to-date before showing the parameter entry page?

like image 694
Behrang Avatar asked Oct 11 '17 05:10

Behrang


People also ask

How do you set parameters in Jenkins pipeline?

Using build parameters, we can pass any data we want: git branch name, secret credentials, hostnames and ports, and so on. Any Jenkins job or pipeline can be parameterized. All we need to do is check the box on the General settings tab, “This project is parameterized”: Then we click the Add Parameter button.

What should be done first for running a pipeline build in Jenkins?

Step 1: Log into Jenkins and select 'New item' from the dashboard. Step 2: Next, enter a name for your pipeline and select 'pipeline' project. Click on 'ok' to proceed. Step 3: Scroll down to the pipeline and choose if you want a declarative pipeline or a scripted one.

How do I change the build parameters in Jenkins?

To execute the Jenkins job from Jenkins web interface first go to respective project workspace and then click on “Build with Parameters” option from left panel. After that, you will be asked to choose/set parameter value (In my project I have set BROWSER parameter.)


1 Answers

Short answer: No. It would be nice if there was some facility for parsing and processing the Jenkinsfile separate from the build, but there's not.

Jenkins does not know about the new parameters until it retrieves, parses, and runs the Jenkinsfile, and the only way to do that is to...run a build.

In effect, the build history will always be "one run behind" the Jenkinsfile; when you change something in the Jenkinsfile, the next build will run with the "old" Jenkinsfile, but pick up and process the new Jenkinsfile for the build after that.

like image 100
dolphy Avatar answered Nov 11 '22 20:11

dolphy