Policy Management - Break Build
Overview
The ability to configure a policy violation to break the build (i.e., fail the PR) for a Code Repository Integration project is now being released as GA together with the other features in version 3.30 (it had previously been released to BETA customers). Now, as part of the policy configuration, you can turn on the Break Build toggle for each policy for which you want a violation to prevent the PR from being merged.
The break build behavior will only be effective if you configure your SCM to block PRs when a Checkmarx One Break Build policy is violated. The procedure for setting up this configuration is different for each SCM, see below for details.
Configuring a Policy Rule to Break Build
Create a policy, including creating one or more rules for the policy, as described in Creating a Policy.
Turn ON the toggle next to the type of rule that you selected:
for All Scanners
or By Scanner.
Click on Save Policy at the top of the screen.
Setting up Your SCM to Break Build
In order for the break build behavior to be effective you need to configure your SCM to block PRs when a Checkmarx One Break Build policy is violated. The procedure for setting up this configuration for each of the supported SCMs is described below.
GitHub (Cloud and Self-Hosted)
For the repo that you want to protect, open the repo settings and go to Code and automation > Branches > Branch protection rules.
Create a rule (or edit an existing rule), specifying the Branch name pattern for the branches that you want to protect.
In the Protect matching branches section, select the checkbox for Require status checks to pass before merging.
In the Status checks that are required section, enter Checkmarx.
Save your rule.
GitLab (Cloud and Self-Hosted)
Open the project settings for the project that you would like to protect and go to Merge requests.
In the Merge checks section, select the checkbox for All threads must be resolved.
Click on Save changes.
Once this configuration is in place, when a Break Build policy violation occurs, Checkmarx will ensure that there is a thread with Unresolved status, which will prevent the merge from being allowed.
Warning
For the GitLab integration, it is possible for a user to manually override the Break Build by clicking on the Resolve button for the unresolved thread and then merging the code.
Bitbucket Cloud
The following procedure describes how to set up Break Build for a specific repo. Alternatively, you can take similar steps on the project level so that all repos in that project will have Break Build functionality.
Prerequisites
Only supported for Bitbucket Premium plan
Procedure
Open the repo settings and go to Workflow > Branch restrictions.
Click on Add a branch restriction.
In the Select branches section, specify the branches that you want to protect.
Open the Merge settings tab.
In the Merge checks section, select the checkbox next to Minimum number of successful builds for the last commit with no failed builds and no in progress builds, and specify the number suitable for your workflow.
In the Merge conditions section, select the checkbox next to Prevent a merge with unresolved merge checks.
Click Save.
Bitbucket Self-Hosted
The following procedure describes how to set up Break Build for a specific repo. Alternatively, you can take similar steps on the project level so that all repos in that project will have Break Build functionality.
Notice
Procedures may differ slightly depending on the version of Bitbucket that you are using.
Open the repo settings and under Pull requests click on Merge checks.
Click on Add a branch restriction.
In the Minimum successful builds section, select Enabled, and specify the number suitable for your workflow.
Click Save.
Azure DevOps (Cloud and Self-Hosted)
Open the project that you would like to protect and go to Repos > Branches.
Click on more options next to the branch that you want to protect and select Branch policies.
In the Status Checks section, click on the + button.
In the Add status policy dialogue, for Status to check, enter Checkmarx.
For Policy requirement, select the radio button for Required .
Click Save.