For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 a budget pipeline with a verify stage reports budget-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

1

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.

2

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.

3

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 is 1 to 10.

  • Checks concurrency: the maximum number of groups with checks running at the same time. Start between 1 and 3. The accepted range is 1 to 10.

  • Maximum check duration: set this above the high-percentile duration of the pipeline, including the time to schedule the run and provision infrastructure.

4

Prepare the pipeline

The pipeline must take its build from the event rather than a fixed branch, clone the repository, and report its result against the commit it tested.

pipeline.yaml
pipeline:
  properties:
    ci:
      codebase:
        repoName: my-repository
        build: <+input>
  stages:
    - stage:
        type: CI
        spec:
          cloneCodebase: true
5

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 Input
pipeline:
  properties:
    ci:
      codebase:
        build:
          type: branch
          spec:
            branch: <+trigger.branch>

Validate the setup

Run one pull request through the queue before you rely on the configuration.

1

Make a pull request eligible

Complete the reviews, the pull request checks, the conflict evaluation, and the other requirements in the branch rule. The pull request then shows Add to merge queue.

2

Confirm the queued state

After the pull request is admitted, Harness Code locks the source branch, creates the speculative commit, and starts the MergeQueue pipeline. Select View queue, or open Merge Queue from the repository branch view, to see the entry and its state.

3

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:

verify.sh
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.

4

Confirm the merge

When every required check reports success, Harness Code fast-forwards the target branch and the pull request becomes merged. The target branch now points at the commit that was tested.

Onboarding checklist

Use this checklist to confirm a repository is ready before you announce the queue to its contributors:

Troubleshooting

No pipeline starts when a pull request enters the queue

Confirm the trigger is enabled, its payload type is Harness, its event is MergeQueue, and it points at the repository the branch rule protects.

The queue does not advance although the pipeline succeeded

The check identifier in the branch rule must match the identifier the pipeline reports, character for character and with the same casing. Confirm the pipeline reports the check against <+trigger.commitSha>. Until the identifiers match, the entry waits for the maximum check duration and is then removed.

The pipeline tested the wrong code

Confirm the stage clones the codebase, the pipeline input uses <+trigger.branch> rather than a literal branch name, and git rev-parse HEAD in the pipeline equals <+trigger.commitSha>.

A pull request was removed from the queue

Open the pull request activity to find the reason. An entry leaves the queue after a failed required check, a check duration timeout, a conflict with an earlier queued entry, a manual removal, or the queue being disabled on the branch rule.

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?