Set common build parameters for every branch in Jenkins multibranch pipeline
Asked Answered
R

2

6

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

Retread answered 9/2, 2018 at 12:6 Comment(1)
As I know it's not possible to define default parameters for new branches/jobs. So you would have to insert them manually for each new branch or write in Jenkinsfile if you don't change them oftenKnack
R
5

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! :)

Retread answered 9/2, 2018 at 12:34 Comment(0)
H
2

For the latests versions of Jenkins you might get this error: The ‘properties’ section has been renamed as of version 0.8. You can use the parameters directive:

Doc: Pipeline Syntax: Parameters

Here is an example:

pipeline {
  parameters {
    string(name: 'MY_PARAM', defaultValue: '', description: 'My parameter')
  }

  agent {
    label 'docker-slave'
  }

  environment {
    DURATION=240
  }

  stages {

    stage('First Stage') {
      when {
        beforeAgent true
      }
      steps {
        sh  "echo ${params.MY_PARAM}"
      }
    }
  }
}

I hope it helps!

Hallowell answered 9/6, 2020 at 10:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.