Skip to main content
Background Image
  1. Posts/

Different branches have different default parameters in Jenkins

·158 words·1 min· ·
Xianpeng Shen
Author
Xianpeng Shen
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.
Jenkins Linux agent configuration
·298 words·2 mins
Provides a step-by-step guide on how to configure a Jenkins Linux agent, including setting up the Java runtime, creating the node, and troubleshooting common issues.
Jenkins Windows agent configuration
·544 words·3 mins
Provides a step-by-step guide on how to configure a Jenkins Windows agent, including setting up the Java runtime, creating the node, and troubleshooting common issues.
Jenkins upgrade issue "Windows agents won't start" workaround
·331 words·2 mins
This article explains how to resolve the issue of Windows agents not starting after upgrading Jenkins, including the necessary steps to update the Windows Slaves plugin and modify configuration files.
What's the difference between result and currentResult in Jenkins?
·336 words·2 mins
This article explains the difference between result and currentResult in Jenkins pipelines, including examples of how they behave in both declarative and scripted pipelines.
How to backup Jenkins
·214 words·2 mins
This article explains how to backup Jenkins using the ThinBackup plugin and shell scripts, ensuring that your Jenkins configuration and build data are safely stored.