Skip to main content
  1. Posts/

Different branches have different default parameters in Jenkins

·158 words·1 min· ·
Xianpeng Shen
Author
Xianpeng Shen
DevOps & Build Engineer | Python Enthusiast | Open Source Maintainer
Table of Contents

Problem
#

When you use Jenkins multibranch pipeline, you may want to have different default parameters settings for defferent branches build.

For example:

For develop/hotfix/release branches, except regular build, you also want to do some code analyzes, like code scanning, etc. For other branches, like feature/bugfix or Pull Request that you just want to do a regular build.

So you need to have dynamic parameter settings for your multibranch pipeline job.

Solution
#

So for these cases, how to deal with Jenkins multibranch pipeline. Here are some code snippet that is works well in my Jenkinsfile.

	def polarisValue = false
	def blackduckValue = false

	if (env.BRANCH_NAME.startsWith("develop") || env.BRANCH_NAME.startsWith("hotfix")
  || env.BRANCH_NAME.startsWith("release")) {
		polarisValue = true
		blackduckValue = true
	}

  pipeline {
    agent { node { label 'gradle' } }

    parameters {
        booleanParam defaultValue: polarisValue, name: 'Polaris',  summary: 'Uncheck to disable Polaris'
        booleanParam defaultValue: blackduckValue, name: 'BlackDuck', summary: 'Uncheck to disable BD scan'
    }

    stages {
      // ...
    }
  }

Related

Jenkins Multibranch Pipeline

·405 words·2 mins
Discusses the use of Jenkins Multibranch Pipeline to manage multiple branches in a project, enabling parallel builds for pull requests and efficient code review processes.