This guide walks you through installing and operating your own Buildkite agents, the small programs that pick up build jobs and run them on your servers. Buildkite is a continuous integration (CI) service, meaning it runs your tests and deployments automatically whenever the code changes, and it splits the work in two. The web interface, the scheduling, and the pipeline editing stay with Buildkite as a hosted service, while every agent runs on hardware you own. Your source code, secrets, and build artifacts stay on your infrastructure, and you have no CI database of your own to operate. By the end you will have an agent installed on Ubuntu, queues and tags routing jobs to the right hosts, hooks that supply secrets, and a scaling pattern that fits your load.
How to verify
buildkite-agent --version
systemctl status buildkite-agent
journalctl -u buildkite-agent -n 100
buildkite-agent meta-data exists "build-passed" # inside a step
curl -fsS https://agent.buildkite.com/v3/ping # agent reachability
ls /var/lib/buildkite-agent/hooks/ # global hooks
ls /var/lib/buildkite-agent/builds/ # checkout root
The agent maintains an outbound long-poll connection to agent.buildkite.com. If systemctl status shows the agent running but no jobs are picked up, check for an HTTP proxy stripping Upgrade headers or a firewall closing idle sockets — the symptom is “agent online, jobs queued” with nothing happening.
What’s happening
A Buildkite agent is a single Go binary that polls the SaaS control plane for work. When a job is dispatched, the agent checks out the git repo into /var/lib/buildkite-agent/builds/<agent>/<pipeline>/, executes the step’s command, streams logs back, uploads artifacts, and reports exit status.
Three concepts you need to know:
- Queues — agents register with one or more queue names; pipelines target queues. This is how you route GPU jobs to GPU hosts, mobile jobs to macOS hosts, and Linux jobs to your generic pool.
- Tags — finer-grained selectors than queues (
os=linux,arch=arm64); pipeline steps canagents: { os: linux, arch: arm64 }. - Hooks — shell scripts the agent runs at lifecycle points (
environment,pre-checkout,checkout,pre-command,command,post-command,pre-artifact,post-artifact,pre-exit). Hooks let you inject secrets, swap the checkout, run linters, or cancel a build before it executes.
The security model: a malicious pipeline can do anything the agent’s UID can. So the agent should run as a dedicated user, in a container or VM, with no access to other tenants’ workloads or secrets. This is why a single huge agent box is the wrong shape — one agent per tenant or per criticality class is the right shape.
The procedure
-
Provision an agent token in the Buildkite UI (Agents → New Token). One token per agent fleet — rotate by issuing a new token and rolling agents.
-
Install the agent on Ubuntu:
sudo sh -c 'echo deb https://apt.buildkite.com/buildkite-agent stable main \ > /etc/apt/sources.list.d/buildkite-agent.list' curl -fsSL https://keys.openpgp.org/vks/v1/by-fingerprint/32A37959C2FA5C3C99EFBC32A79206696452D198 \ | sudo gpg --dearmor -o /usr/share/keyrings/buildkite-agent-archive-keyring.gpg sudo apt-get update && sudo apt-get install -y buildkite-agent sudo sed -i "s|^token=.*|token=\"$AGENT_TOKEN\"|" /etc/buildkite-agent/buildkite-agent.cfg -
Configure queue and tags. Edit
/etc/buildkite-agent/buildkite-agent.cfg:name="ci-linux-%spawn" tags="queue=default,os=linux,arch=amd64,zone=internal" spawn=4 # number of worker processes per host priority=10 # higher = picked first build-path="/var/lib/buildkite-agent/builds" hooks-path="/etc/buildkite-agent/hooks" plugins-path="/etc/buildkite-agent/plugins" -
Start.
systemctl enable --now buildkite-agent. Withspawn=4, the unit forks four worker processes; each holds one job. -
Hooks for secrets. Buildkite’s recommended pattern is the
secretsplugin or a globalenvironmenthook that pulls from your vault:#!/usr/bin/env bash # /etc/buildkite-agent/hooks/environment set -eu case "$BUILDKITE_PIPELINE_SLUG" in web-frontend) export AWS_ACCESS_KEY_ID=$(vault kv get -field=access_key secret/ci/web-frontend/aws) export AWS_SECRET_ACCESS_KEY=$(vault kv get -field=secret_key secret/ci/web-frontend/aws) ;; esacThe agent encrypts these env vars on the wire, but they end up in the step’s shell — so a malicious pipeline in
web-frontendcan read them. Scope the hook tightly. -
Pipeline definition. Stored as
.buildkite/pipeline.ymlin the repo:steps: - label: "test" command: "go test ./..." agents: queue: default os: linux - wait - label: "deploy prod" command: ".buildkite/deploy.sh prod" branches: "main" concurrency: 1 concurrency_group: "prod-deploy"concurrency_groupserializes deploys across all branches and builds — Buildkite’s mechanism for “only one prod deploy at a time”. -
Scaling. For variable load, the Buildkite Elastic CI Stack (Terraform/CloudFormation) runs an ASG that grows and shrinks based on queue depth. For steady internal load, a fixed pool of three-to-ten agents per tenant is usually enough. For Kubernetes, the agent runs as a Deployment and the Agent Stack for Kubernetes launches each job in its own Pod.
Common pitfalls
- Shared agent across tenants. Pipeline A reads pipeline B’s checkout cache or environment. Either one agent per tenant or use a job runner that wipes between jobs.
- No
BUILDKITE_CLEAN_CHECKOUT=true. Agents reuse the checkout for speed; if your build pollutes the working tree, subsequent builds inherit the pollution. Set it per pipeline or in the global hook. - Token in
cfgplaintext on a shared host. Use file permissions0600 buildkite-agent:buildkite-agentand consider sourcing the token from systemdCredentials=. - Default
git-mirrors-pathunset. Large repos re-clone every build. Setgit-mirrors-path=/var/lib/buildkite-agent/git-mirrorsand you get bare-repo deltas. - Plugin from an untrusted org. Plugins are arbitrary shell. Pin to a specific tag from a vetted org; review the source.
We host Buildkite agent fleets for clients who like the SaaS scheduler but want their builds running on their own VPC — pulling private images from their internal registry, talking to internal databases, deploying through their own ALB. The agent host hardening, queue layout, secret broker, and scaling rules are operated by our team; the .buildkite/pipeline.yml files live with the dev teams. That shape is part of /en/services/managed-operations/.