---
title: "Buildkite"
description: "Gate a Buildkite pipeline on a TRUSTIVAN policy with the trustivan CLI on your own agents, and upload the SARIF findings as a build artifact."
---

There is no Buildkite plugin from TRUSTIVAN. The recipe downloads the
[`trustivan`](/cli-reference/trustivan) CLI, a single static binary, and runs
`trustivan gate` as a command step. The gate requests a scan, waits for it, asks
for a verdict and exits `1` when the policy blocks the build.

## Prerequisites

- **An API key** with `scans:create`, `scans:read` and `verdicts:request`, plus
  `findings:read` for the SARIF file. Buildkite agents are yours, so expose it
  to the step as `TRUSTIVAN_API_KEY` from the agent's `environment` hook or a
  secrets plugin, never from `pipeline.yml`. See [Scopes](/api-reference/scopes).
- **An enabled policy** in the organization, or a policy id to pass with
  `--policy`. Without one the verdict request answers `409`. See
  [Gate a pipeline on a policy](/tutorials/gate-a-pipeline).
- **The image already pushed** to a registry TRUSTIVAN can pull from. TRUSTIVAN
  pulls it itself, so a registry the agent can reach but TRUSTIVAN cannot will
  fail the scan. A private registry needs a credential stored in TRUSTIVAN first;
  see [Scan a private registry image](/how-to/scan-a-private-registry-image).
- **A Linux agent** with `curl` and `sha256sum`, and outbound HTTPS to
  `github.com` and to your TRUSTIVAN deployment.

## The pipeline

```yaml .buildkite/pipeline.yml
steps:
  # Your build-and-push step goes first; the gate needs the pushed image.
  - wait

  - label: "TRUSTIVAN policy gate"
    env:
      TRUSTIVAN_URL: https://app.trustivan.com
    command: |
      set -eu
      base=https://github.com/trustivan/trustivan/releases/latest/download
      curl -fsSLO "$$base/trustivan-linux-amd64"
      curl -fsSLO "$$base/SHA256SUMS"
      grep ' trustivan-linux-amd64$$' SHA256SUMS | sha256sum -c -
      chmod +x trustivan-linux-amd64
      ./trustivan-linux-amd64 gate \
        --image "registry.example.com/acme/api:$$BUILDKITE_COMMIT" \
        --idempotency-key "$$BUILDKITE_BUILD_ID" \
        --sarif trustivan.sarif
    artifact_paths:
      - trustivan.sarif
```

Every `$` is doubled. Buildkite interpolates `$VAR` in `pipeline.yml` when the
pipeline is uploaded, and `$$` is how a dollar reaches the shell intact; with
single dollars, `$base` would be replaced by an empty string before the step
runs. `$BUILDKITE_BUILD_ID` is the idempotency key, so a retried request inside
one build reuses its scan instead of queueing a second one. To pin a CLI
release, replace `latest/download` with `download/<tag>`.

## What it gates on

| Exit code | Meaning |
|---|---|
| `0` | The policy passed |
| `1` | The policy blocked the build. The job log shows `TRUSTIVAN policy gate: FAIL` and the rules that fired |
| `2` | TRUSTIVAN could not answer: missing key, network, timeout, a failed scan, no policy. The log line starts `trustivan:` and names the cause |

Buildkite fails the job on both. A failed scan is never treated as a pass. The
default wait is 20 minutes; change it with `--timeout 30m`.

To let a new policy report before it is enforced, mark exit `1` as a soft
failure, so a block shows on the job and does not fail the build, while exit
`2` still does:

```yaml
    soft_fail:
      - exit_status: 1
```

## See the results

- **The job log** has the verdict, the policy and version, the scan id and
  every rule, with `!` beside the ones that fired.
- **The job's Artifacts tab** has `trustivan.sarif`, which any SARIF 2.1.0
  viewer opens.
- **The dashboard** has the scan and its findings under the asset.

## Troubleshooting

| Symptom | Cause |
|---|---|
| `TRUSTIVAN_API_KEY is not set` | The agent hook or secrets plugin did not export it for this step |
| `curl` fails with error `(3)`, or the image tag is empty | A single `$` was interpolated at upload. Double it |
| `sha256sum: WARNING: 1 computed checksum did NOT match` | The download was cut short or altered. Do not run the file |
| `... (401)` / `... (403)` | The key is wrong or expired, or lacks a scope (`findings:read` with `--sarif`). See [Rotate an API key](/how-to/rotate-an-api-key) |
| `... /verdict: ... (409)` | No policy is enabled for the organization |
| `the scan failed (...)` | TRUSTIVAN could not pull or read the image. Check the reference and the registry credential |

## See also

- [`trustivan` CLI reference](/cli-reference/trustivan): every flag
- [CI pipelines](/integrations/ci-pipelines): the same gate with `curl`, and a
  certificate check with `tls-check`
- [PagerDuty](/integrations/pagerduty): page on a blocking verdict
