How to allowlist additional branches for Only Build Pull Requests

Overview

In some cases, you may wish to add additional default branches to your project on CircleCI. This is now possible via the v1.1 API.

This feature expands on the Only Build Pull Request offering by enabling our users to configure additional default branches outside of the default in your VCS. 

 

⚠ This is an override and not an addition. ⚠ 
You will need to specify all current default branches for your project if you decide to add more.

 

How to find your current default branches on CircleCI:

We can do this programmatically with JQ:

curl -X GET \
--header "Circle-Token: <token>" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
'https://circleci.com/api/v1.1/project/<vcs-type>/<org-slug>/<project-slug>/settings' | jq '.feature_flags."pr-only-branch-overrides"'

Once you have your current default branches, you can move on to the next step.

 

Example 1:

In this example, we will be adding the default branches gh-readonly-queue.* along with staging with main as our current default. 

curl -X PUT \
--header "Circle-Token: <token>" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '{"feature_flags":{"pr-only-branch-overrides": "main, gh-readonly-queue.*, staging"}}' \
'https://circleci.com/api/v1.1/project/<vcs-type>/<org-slug>/<project-slug>/settings'

Result: If the response looks like the following:

""%

Any branch that starts with gh-readonly-queue, such as gh-readonly-queue/feat/release or gh-readonly-queue-feat-123, and any branch that starts with staging will now trigger validation on all commits. Additionally, the default branch, main, will continue to build all commits.

 

Example 2: 

In this example, we will be adding the default branches \\(\\d+\\)-release.* along with main as our current default.

curl -X PUT --header "Circle-Token: <token>" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '{"feature_flags":{"build-prs-only":true, "pr-only-branch-overrides": "main, \(\\d+\)-release.*"}}' \
'https://circleci.com/api/v1.1/project/<vcs-type>/<org-slug>/<project-slug>/settings'

Result: Will build any branch that starts with one or more digits enclosed in parenthesis followed by the string -release suffixed with zero or more characters. For example:

Branches (123)-release2 , (7)-release-to-prod, and (334)-release will all trigger validation on all commits. Additionally, the default branch, main, will continue to build all commits.

 

Additional Resources

 

Was this article helpful?
1 out of 1 found this helpful

Comments

0 comments

Article is closed for comments.