Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I override a jenkinsfile's default parameters?

Sometimes, we want to create multiple jobs that use the same Jenkinsfile instead of a single one. This could happen for example because we want to maintain logs divided based on parameters, instead of having a single job on which look for the right log.

However, in this case, we can't use the parameter definition in the Jenkinsfile, because whatever default value we would define on the job instance would be overwritten by the following execution with whatever is defined in the Jenkinsfile (and this is also happening if we don't define a default value).

So, in this situation, the only way we figure out is to remove the parameter definition in the Jenkinsfile and define the parameters directly on the jobs, which is kind of not optimal.

I mean, I agree that this is the right behavior in most of the cases, as you don't want your parameter to be out of synch and not versioned, but is there a way to specify to Jenkins to skip the parameter reconfiguration or to override the default parameter written in the Jenkinsfile? Something that can be activated/deactivated job by job.

like image 497
Mikyjpeg Avatar asked Sep 01 '19 11:09

Mikyjpeg


1 Answers

Had this problem myself, we solved it like this:

string(name: 'parameterName', defaultValue: params.parameterName ?:'your default value')

Now the default values defined through Jenkins job configuration will not be overridden.

like image 119
finderAUT Avatar answered Nov 04 '22 07:11

finderAUT