Overriding default Multibranch Pipeline job parameters defined in a Jenkinsfile

3,347 views
Skip to first unread message

Sebastian Nowicki

unread,
Jun 13, 2016, 10:37:50 AM6/13/16
to Jenkins Users
Hi,

I have create a parameterised Multibranch Pipeline job, defining the parameters and their defaults in a Jenkinsfile inside the repository being built.

The job will be built on multiple environments, with separate Jenkins deployments. The defaults set in the Jenkinsfile are production values, but I'd like to be able to set different values globally in the other deployments. Is there any way to override the default value globally for the whole job?

I've found the Environment Injector plugin, but it doesn't seem like it's possible to customize a job which uses a Jenkinsfile.

Hans Kristian Flaatten

unread,
Jan 4, 2017, 6:03:43 AM1/4/17
to Jenkins Users
I have the exact same problem! Did you ever find a solution or workaround, Sebastian?

Sebastian Nowicki

unread,
Jan 6, 2017, 11:53:14 AM1/6/17
to Jenkins Users
Unfortunately, no. I suppose one solution would be to remove environment specific stuff from the build phase and specify environment specific settings when running the application. May not be a viable solution for you though.

Martin Pradny

unread,
Feb 24, 2017, 6:25:50 PM2/24/17
to Jenkins Users
I was dealing with similar issue today and only place that I could use to store config was credentials secret text. I stored config as a map and in pipeline, within withCredentials block, I used Eval statement to convert it to proper map, so I could use current branch name as a key to get value. Works quite ok for me as I can have different configs on different servers now.

M.

Abir M

unread,
Feb 25, 2017, 11:35:44 PM2/25/17
to Jenkins Users
Hi,
With the declarative pipeline syntax one of the following options might help:

1) Since you already define parameters in the Jenkinsfile, in the options section, you can disable automatic triggering of the job for non-prod instances of Jenkins or for non-master branches. Now either run the job manually, overriding the default parameter values, or trigger them some other way. e.g.

overrideIndexTriggers(env.BRANCH_NAME == 'master')

overrideIndexTriggers(env.JENKINS_URL =~ "jenkins-prod.example.com")

2) Move the parameter to the environment section and define programmatically based on a global Jenkins environment variable, or a global property. 

environment {
  deploymentServer = "${JENKINS_URL}" =~ "jenkins-prod" ? "prod-server" : "dev-server"
Reply all
Reply to author
Forward
0 new messages