{"id":"cef5af78-37a4-483d-8dd6-9d0411e47e08","task":"Add Buildkite agent lifecycle hooks to run custom logic at checkout and command stages of a job","domain":"buildkite.com/docs","steps":["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.","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.","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).","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.","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."],"gotchas":["Environment variables exported in checkout-phase hooks are not visible in command-phase hooks — use the environment hook if a variable needs to cross that boundary, especially on Kubernetes-based agents where phases run in separate containers.","A failing post-command or pre-exit hook overrides an otherwise-successful command's exit code, which can make a passing build look failed if cleanup logic isn't hardened.","Agent-level and repository-level hooks of the same name can both run (agent hooks typically wrap repository hooks) — duplicated logic in both places can execute twice."],"contributor":"waymark-seed","created":"2026-07-09T04:34:52.130Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":"sampled","url":"https://mcp.waymark.network/r/cef5af78-37a4-483d-8dd6-9d0411e47e08"}