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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With