A Jenkins pipeline project is configured to fetch its Jenkinsfile
from a Git repo:
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:
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?
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.
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.
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.)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With