Set Up Merge Queue
Configure the branch rule, Harness CI pipeline, and MergeQueue trigger that a Harness Code repository needs before it can use Merge Queue.
Merge Queue is configured per repository, because the required checks and the pipeline that produces them are repository-specific. This topic covers the branch rule, the pipeline, and the MergeQueue trigger, then validates the result with a test pull request. Go to Merge Queue Overview to review the model before you configure it.
Before you begin
Confirm the following before you create the branch rule:
A Harness CI pipeline: the repository has a pipeline that clones the repository and runs the tests you want to gate merges on.
A known check identifier: you know the exact identifier the pipeline reports. A Harness CI check commonly takes the form
<pipeline-identifier>-<stage-identifier>, so abudgetpipeline with averifystage reportsbudget-verify. Confirm the value from a successful run rather than assuming it.Reliable checks: the checks you intend to require pass consistently. Go to Merge Queue Overview to see what a flaky check costs a queue.
Repository administrator access: you can create and edit branch rules on the repository. Go to Rules to review how branch rules work.
Agreement on the restriction: the repository owners accept that direct updates to the protected branch are blocked while the queue is active.
Configure the repository and pipeline
Create the branch rule
In the repository, go to Settings, select Rules, then click Create rule and select Create branch rule.
Give the rule a descriptive name and set the target branch or branch pattern it applies to. Configure the required approvals, the protections you want to keep, and the bypass policy in the same rule.
Select the pull request checks
Under Require status checks to pass, select the checks that decide whether a pull request is eligible to enter the queue.
Pull request checks and Merge Queue checks answer different questions. A pull request check decides whether a pull request may join the queue. A Merge Queue check validates that pull request against the cumulative queued state. The same pipeline and identifier can serve both purposes.
Enable Merge Queue
Select Require merge queue, then configure its settings:
Status checks: enter the exact, case-sensitive identifier the Merge Queue pipeline reports. A mismatch leaves the queue waiting until the check duration expires, even when the pipeline succeeds.
Merge group size: the maximum number of consecutive entries that one speculative commit validates. Start at
1. The accepted range is1to10.Checks concurrency: the maximum number of groups with checks running at the same time. Start between
1and3. The accepted range is1to10.Maximum check duration: set this above the high-percentile duration of the pipeline, including the time to schedule the run and provision infrastructure.
Leave the up-to-date requirement disabled
Do not enable Require branch to be up to date before merging alongside Merge Queue. The queue already validates each change against the correct target-branch state, and the two settings together return contributors to the rebase loop the queue exists to remove.
Create the MergeQueue trigger
In the pipeline, go to Triggers, then click New Trigger. Set the payload type to Harness, select the repository, set the event to MergeQueue, and enable the trigger.
Set the pipeline input so the build resolves from the trigger:
pipeline:
properties:
ci:
codebase:
build:
type: branch
spec:
branch: <+trigger.branch>Never hard-code the branch
A literal value such as branch: main makes CI clone the tip of the target branch instead of the speculative commit. The pipeline succeeds, the check reports against code the queue never intended to test, and the target branch fast-forwards to a commit nothing validated.
Validate the setup
Run one pull request through the queue before you rely on the configuration.
Verify that the speculative commit was tested
Add a step to the pipeline that compares the checked-out commit against the commit the trigger supplied:
set -e
SPEC="<+trigger.commitSha>"
HEAD="$(git rev-parse HEAD)"
echo "trigger.commitSha=$SPEC"
echo "HEAD=$HEAD"
test "$HEAD" = "$SPEC"The comparison must pass. A passing comparison proves CI tested the speculative commit rather than the source branch or the tip of the target branch.
Onboarding checklist
Use this checklist to confirm a repository is ready before you announce the queue to its contributors:
Troubleshooting
Next steps
Go to Merge Queue Overview to read how batching, concurrency, and queue states affect throughput once the queue carries real traffic. Go to Rules to review the other protections available on the same branch rule.
Last updated
Was this helpful?