Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict health metrics by branches in a multi branch pipeline job

In a multibranch Jenkins job, you can decide to show health metrics and they are obtained from the branch with the worse health. This is fine, except that it is common to have feature branches that fail and thus bring a poor general status to the project. Is it possible to restrict the health metrics to consider only the master and development branches?

like image 451
Uko Avatar asked Jan 24 '18 07:01

Uko


People also ask

What is the difference between a normal pipeline and multibranch pipeline?

A normal pipeline job is meant for building a single branch from the SCM and deploy to a single environment. However, you can. A multibranch pipeline is meant for building multiple branches from a repository and deploy to multiple environments if required.

What is a Jenkins multi-branch pipeline?

Jenkins’s multi-branch pipeline is one of the best ways to design CI/CD workflows as it is entirely a git-based (source control) pipeline as code. This guide will talk about all the key concepts involved in a Jenkins multi-branch pipeline setup.

How do I add a branch filter to my build pipeline?

Select Pipelines, and then choose Builds. Locate the build pipeline that services your main branch. Select Edit. Select the Triggers menu for your build. Ensure you have Continuous integration enabled. Select the + Add icon under Branch filters.

How do I protect the master branch in azure pipelines?

Azure Pipelines or TFS repository. Navigate to the Repos hub in Azure Repos or TFS. Choose your repository and select Branches. Choose the master branch. You will implement a branch policy to protect the master branch. Select the ellipsis to the right of your branch name and select Branch policies. Choose the checkbox for Protect this branch.


1 Answers

You can try to change the healthMetrics node over a configure block:

configure { node ->
  node.remove(node.get('healthMetrics'))
  node / 'healthMetrics' << 'jenkins.branch.PrimaryBranchHealthMetric' {}
}

My approach was to change the health metric manually via the Web UI and compare the resulting XML of the job by appending config.xml to my job's URL like so: https://jenkins.example.com/job/my-folder/job/my-multibranch-pipeline-job/config.xml.

This Jenkins Job DSL Playground lets you easily try out the configure block.

like image 134
Matthias Avatar answered Sep 23 '22 07:09

Matthias