docs guides CI with any builder
09-ci-with-any-builder.md GuidesNov 22, 2026

CI with any builder

GitStack has a named connector for Buildkite. Any other builder, including one you wrote, connects through the Webhook connector. Its contract is fixed:

  • Out: GitStack sends each build request as a signed POST of JSON to a URL you choose.
  • In: your builder reports each check to the checks API with the integration's token.

The checks it reports gate landing like any other CI, pinned as webhook:<name>.

Connect the builder#

  1. Open the repository's Settings, then CI checks.
  2. Under Connect Webhook, enter the Builder URL, the HTTPS address GitStack posts build requests to, then Connect.
  3. Copy what GitStack shows:
    • Signing secret, to verify each request.
    • Checks API, https://gitstack.sh/api/v1/repos/<namespace>/<name>/commits/{sha}/checks.
    • Fetch token, which starts with gsi_. It is shown this once. It can clone the repository and post checks.

Then require the checks your builder will report in .gitstack/policy.toml, and land that change as a review:

toml
[checks]
required = ["webhook:lint", "webhook:test"]

Build requests#

GitStack sends a build request for each of these events:

event When ref
review A land needs the review's checks, someone presses Run checks, or gs review ci refs/heads/<review branch>
main After every land, for the default branch's new tip refs/heads/<default branch>
push A push to a branch that [ci] branches matches refs/heads/<branch>
tag A new tag that [ci] tags matches refs/tags/<tag>
rerun A re-run of one check (see Re-runs) empty
cancel Stop a build GitStack no longer needs (see Cancels) empty
event
review
When
A land needs the review's checks, someone presses Run checks, or gs review ci
ref
refs/heads/<review branch>
event
main
When
After every land, for the default branch's new tip
ref
refs/heads/<default branch>
event
push
When
A push to a branch that [ci] branches matches
ref
refs/heads/<branch>
event
tag
When
A new tag that [ci] tags matches
ref
refs/tags/<tag>
event
rerun
When
A re-run of one check (see Re-runs)
ref
empty
event
cancel
When
Stop a build GitStack no longer needs (see Cancels)
ref
empty

The request is a POST with a JSON body:

json
{
  "delivery": "01JD3T8Q4K7M2X9N5B6C0VWYZA",
  "event": "review",
  "repo": "acme/api",
  "ref": "refs/heads/billing",
  "sha": "9f3e2d1c4b5a6d7e8f90a1b2c3d4e5f6a7b8c9d0",
  "review": "R12",
  "stack": "billing",
  "integration": "01JD3SZ6PX0E3J8H1QF2M4R7TN",
  "clone_url": "https://gitstack.sh/acme/api.git"
}
Field Meaning
delivery The request's id. It stays the same when the request is sent again.
event review, main, push, tag, rerun or cancel.
repo The repository, <namespace>/<name>.
ref The full ref the event is about.
sha The full commit id to build.
review The review id, on review requests only.
stack The review's branch, on review requests only.
integration The integration's id.
clone_url Where to clone from, with the fetch token as the git password.
rerun On a re-run, the name of the check to run again.
failed_only On a re-run, true: run only what failed.
cancel On a cancel, the delivery whose build to stop.
Field
delivery
Meaning
The request's id. It stays the same when the request is sent again.
Field
event
Meaning
review, main, push, tag, rerun or cancel.
Field
repo
Meaning
The repository, <namespace>/<name>.
Field
ref
Meaning
The full ref the event is about.
Field
sha
Meaning
The full commit id to build.
Field
review
Meaning
The review id, on review requests only.
Field
stack
Meaning
The review's branch, on review requests only.
Field
integration
Meaning
The integration's id.
Field
clone_url
Meaning
Where to clone from, with the fetch token as the git password.
Field
rerun
Meaning
On a re-run, the name of the check to run again.
Field
failed_only
Meaning
On a re-run, true: run only what failed.
Field
cancel
Meaning
On a cancel, the delivery whose build to stop.

review, stack, rerun, failed_only and cancel are left out when they don't apply. The request's headers:

Header Value
Content-Type application/json
User-Agent GitStack-Webhook
X-GitStack-Event The event field
X-GitStack-Delivery The delivery field
X-GitStack-Signature t=<unix seconds>,v1=<hex>
Header
Content-Type
Value
application/json
Header
User-Agent
Value
GitStack-Webhook
Header
X-GitStack-Event
Value
The event field
Header
X-GitStack-Delivery
Value
The delivery field
Header
X-GitStack-Signature
Value
t=<unix seconds>,v1=<hex>

Answer with any 2xx status as soon as you have the request; GitStack doesn't read the body. Build afterward, and report what you find through the checks API.

Verify the signature#

v1 is the hex HMAC-SHA256 of <t>.<body>, keyed with the signing secret, where <t> is the t value and <body> is the raw request body. Check it against the bytes you received, before parsing them. Each attempt is signed when it is sent, so you can also refuse an old t:

python
import hashlib
import hmac
import time


def verify(header: str, body: bytes, secret: str) -> bool:
    parts = dict(p.split("=", 1) for p in header.split(",") if "=" in p)
    t = parts.get("t", "")
    if not t.isdigit() or abs(time.time() - int(t)) > 300:
        return False
    mac = hmac.new(secret.encode(), t.encode() + b"." + body, hashlib.sha256)
    return hmac.compare_digest(mac.hexdigest(), parts.get("v1", ""))

Report checks#

Post each check to the checks API with the fetch token:

bash
curl -sS -X POST "https://gitstack.sh/api/v1/repos/acme/api/commits/$SHA/checks" \
  -H "Authorization: Bearer $GITSTACK_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "test", "outcome": "running", "url": "https://ci.example.com/runs/812", "external_id": "812"}'

$SHA is the full, lowercase commit id from the request. Post again with the result when the check finishes; the newest report of a check replaces the one before.

Field Required Meaning
name yes The check's name, one line of at most 100 characters. The policy requires it as webhook:<name>.
outcome yes running, pass, fail, cancelled or skipped.
url no The run's page, an http or https URL. The review links the check to it.
external_id no Your id for the run, at most 200 characters. Re-runs need it.
summary no One line about the result, at most 300 characters, such as 12 failed of 340. It shows under the check's name on the review and on the repository's home page, as plain text.
Field
name
Required
yes
Meaning
The check's name, one line of at most 100 characters. The policy requires it as webhook:<name>.
Field
outcome
Required
yes
Meaning
running, pass, fail, cancelled or skipped.
Field
url
Required
no
Meaning
The run's page, an http or https URL. The review links the check to it.
Field
external_id
Required
no
Meaning
Your id for the run, at most 200 characters. Re-runs need it.
Field
summary
Required
no
Meaning
One line about the result, at most 300 characters, such as 12 failed of 340. It shows under the check's name on the review and on the repository's home page, as plain text.

What each outcome means for a land:

outcome The land
running Waits.
pass Counts the check as passing.
fail Refuses, and names the check.
cancelled Counts the check as not reported yet.
skipped Counts the check as passing.
outcome
running
The land
Waits.
outcome
pass
The land
Counts the check as passing.
outcome
fail
The land
Refuses, and names the check.
outcome
cancelled
The land
Counts the check as not reported yet.
outcome
skipped
The land
Counts the check as passing.

A check left at running keeps the land waiting, since GitStack can't ask a webhook builder how a run is going. Always post a final outcome.

The API answers 201 with the check it recorded. Errors:

Status code Why
400 bad_request The body isn't JSON, or is over 16 KiB.
422 invalid_check A field is out of range: the name, the outcome, the URL, or the length of summary or external_id.
401 unauthorized The token is missing, or belongs to another repository.
404 unknown_commit The repository has no such commit.
409 not_requested GitStack never sent this integration a build request for the commit.
403 token_scope The token lacks the checks scope.
403 forbidden A person's token or session. Only an integration token can post checks.
Status
400
code
bad_request
Why
The body isn't JSON, or is over 16 KiB.
Status
422
code
invalid_check
Why
A field is out of range: the name, the outcome, the URL, or the length of summary or external_id.
Status
401
code
unauthorized
Why
The token is missing, or belongs to another repository.
Status
404
code
unknown_commit
Why
The repository has no such commit.
Status
409
code
not_requested
Why
GitStack never sent this integration a build request for the commit.
Status
403
code
token_scope
Why
The token lacks the checks scope.
Status
403
code
forbidden
Why
A person's token or session. Only an integration token can post checks.

The integration and its kind come from the token, never from the body, so a check required as webhook:test can only be met by a webhook integration. GitStack takes checks only on commits it sent your builder a request for, so a build your builder starts on its own never gates a land.

The token's rights#

The fetch token can clone and fetch the repository, including review commits a plain clone doesn't download, and post checks. Use any username with it as the git password. In Settings, CI checks, New token makes a token with more rights and replaces the old one:

Right Lets the token
checks Post checks. A webhook integration's token always has it.
tags Create tags on landed commits (see gs tag for the rules), by git push or POST /api/v1/repos/<namespace>/<name>/tags with {"tag": "v1.4.0", "sha": "<full commit id>"}. It can never move or delete one.
branches Push the branches that match the patterns you give it, such as release/*. Never the default branch or a review branch.
comment Post a comment on a review with POST /api/v1/repos/<namespace>/<name>/reviews/<review id>/integration_comments and {"body": "<markdown>"}, shown as the integration with a bot label.
Right
checks
Lets the token
Post checks. A webhook integration's token always has it.
Right
tags
Lets the token
Create tags on landed commits (see gs tag for the rules), by git push or POST /api/v1/repos/<namespace>/<name>/tags with {"tag": "v1.4.0", "sha": "<full commit id>"}. It can never move or delete one.
Right
branches
Lets the token
Push the branches that match the patterns you give it, such as release/*. Never the default branch or a review branch.
Right
comment
Lets the token
Post a comment on a review with POST /api/v1/repos/<namespace>/<name>/reviews/<review id>/integration_comments and {"body": "<markdown>"}, shown as the integration with a bot label.

A branch the token pushes never starts a build on its own integration, so a job that pushes a branch can't start itself again.

Retries and duplicates#

When your URL doesn't answer 2xx within 10 seconds, or the connection fails, GitStack sends the request again: after 30 seconds, then waiting twice as long each time, up to an hour between attempts, for 24 hours. A redirect counts as a failure, since GitStack never follows one.

A request keeps its delivery id on every attempt, and when GitStack asks about the same event, ref and commit again (a second land of the same review, say). Use it to avoid running one build twice at once: if a delivery you are still building arrives again, keep the build you have. If that build already finished, build again.

When a land asks for a build and the request fails, the land answers that starting the checks failed, and the retries continue in the background.

Re-runs#

GitStack asks your builder to run a check again in two cases:

  • Run checks or gs review ci on a review whose check failed or was cancelled.
  • Auto-revert, when a land turns a required check red on the default branch: it asks for one re-run to rule out a flaky test before it reverts (see When a land breaks the branch).

A re-run is a new request with its own delivery id. Its event is rerun, rerun names the check, sha is the commit, and failed_only is true. GitStack only asks again about a check that reported an external_id, so send one with each check. Without it, Run checks sends a plain request instead, and auto-revert can't rule out a flaky test, so it only comments on the review and reverts nothing.

Cancels#

GitStack asks your builder to stop a build in two cases:

  • Someone cancels a review's checks (the review page, or the API's POST .../checks/cancel).
  • A land moves the default branch past a main build that is still running. Auto-revert's own builds are never cancelled (see When a land breaks the branch).

A cancel is a new request with its own delivery id. Its event is cancel, cancel is the delivery of the build to stop, and sha is its commit. Stop that build if it still runs, and report its checks as usual; a check you report as cancelled counts as no result. A builder that ignores cancels keeps working: the build just runs to its end.

Addresses GitStack won't deliver to#

The Builder URL must use HTTPS, and can't carry a user name, password or #fragment. GitStack refuses to deliver to these addresses, checked after the name resolves, on every request:

  • loopback, such as 127.0.0.1 and ::1
  • private networks: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7, and the shared range 100.64.0.0/10
  • link-local addresses, 169.254.0.0/16 and fe80::/10, which include the cloud metadata address 169.254.169.254
  • fd00:ec2::254, another cloud metadata address
  • unspecified and multicast addresses

Requests don't go through a proxy set in the server's environment.

A self-hosted server whose builder is on its own network can allow private addresses with GITSTACK_CI_WEBHOOK_ALLOW_PRIVATE=true. Loopback, link-local and metadata addresses stay refused. See Configuration.