Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set common build parameters for every branch in Jenkins multibranch pipeline

I have a Jenkins multibranch item and several branches where the Jenkins pipeline file is. I also have several common parameters which are actual for every of those branches (like test Groups to run, selenium properties etc.)

How can I define the set of those parameters in Jenkins interface so they will appear for each run of branch so that each new branch automatically becomes as "Parameterized build"? I can see this flag in the configuration of particular branch build (can't save it, though):

enter image description here

But not in the multibranch item's configuration.

Jenkins 2.89.3

like image 857
BohdanN Avatar asked Feb 09 '18 12:02

BohdanN


People also ask

How do you add parameters in Multibranch pipeline Jenkins?

If you want to add new parameters you have to do it using properties in Jenkinsfile - goto <JENKINS URL>/pipeline-syntax and generate code for the properties step.

How do I configure multiple branches in Jenkins?

Step 1: From the Jenkins home page create a “new item”. Step 2: Select the “Multibranch pipeline” from the option and click ok. Step 3: Click “Add a Source” and select Github. Step 4: Under the credentials field, select Jenkins, and create a credential with your Github username and password.

Which enables you to implement different Jenkinsfiles for different branches of the same project?

The Multibranch Pipeline project type enables you to implement different Jenkinsfiles for different branches of the same project.


1 Answers

I just needed to define them in properties step in the pipeline...

 properties([
                parameters([
                        string(name: 'one', defaultValue: ''),
                        string(name: 'second', defaultValue: ''),
                        string(name: 'third', defaultValue: ''),
                ])
        ])

It's a magic! :)

like image 157
BohdanN Avatar answered Oct 10 '22 01:10

BohdanN