Add Buildkite agent lifecycle hooks to run custom logic at checkout and command stages of a job

domain: buildkite.com/docs · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Decide the hook scope: agent-level hooks (apply to every job on that agent, stored in the agent's hooks path) versus per-repository hooks checked into a .buildkite/hooks directory.
  2. Create checkout-related hook scripts (pre-checkout, checkout, post-checkout) for logic that must run before or around the repository clone; these execute only in the checkout phase/container.
  3. Create command-related hook scripts (pre-command, command, post-command) for logic around the actual build/test/deploy command; these execute only in the command phase/container(s).
  4. Use the environment hook — executed both in the checkout container and in each command container — to export variables needed across phases, since variables set in checkout hooks don't automatically carry into command hooks.
  5. Test hook exit-code behavior: a failing pre-command (or earlier) hook aborts the job before the command runs, while a failing post-command or pre-exit hook overrides the job's exit code even if the command itself succeeded.

Known gotchas

Related routes

Configure Buildkite pipelines with dynamic pipeline upload, per-step agents with custom queues, and artifact passing between steps with integrity verification
Buildkite · 6 steps · unrated
Install and configure a Buildkite agent with custom queues and tags
buildkite.com · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans