1. Resources
  2. /
  3. Examples
  4. /
  5. Agent Hooks

Buildkite Agent Hooks Example

This repository demonstrates how to use Buildkite Agent hooks to control which teams may run pipelines on specific agents or groups of agents.

👉 See these examples in action:

See the full Getting Started Guide and Buildkite Agent Overview for step-by-step instructions on how to get this running.

Successful build screenshot

Allowed team member build succeeded

Rejected build screenshot

Unapproved team member build rejected by the hook


How it works

Buildkite agents expose environment variables about the jobs they run, and allow you to define hooks to customize job behavior. By combining agent hooks with the environment variables exposed by Buildkite agents, you can enforce policies or restrict access based on job context - before a command even runs.

This example uses the environment hook (located at agent/hooks/environment) to restrict job execution based on team membership. While this example focuses on the environment hook, Buildkite also supports other lifecycle hooks, such as pre-command and post-command, which can be used for cleanup, auditing, or advanced workflow control.

The environment hook runs before code is checked out, making it ideal for early policy enforcement.

You can use this technique to:

  • Restrict access to dedicated queues
  • Enforce team-level separation on shared infrastructure
  • Implement custom scheduling or resource constraints

Setup

  1. Install the Agent Hook

Install the environment hook on your agents:

  cp agent/hooks/environment /etc/buildkite-agent/hooks/environment
  chmod +x /etc/buildkite-agent/hooks/environment

🛠️ If using hosted agents, the hook can be preinstalled during agent setup.

  1. Use Dedicated Queues (Optional)

If you’re using this policy on only some agents, isolate them using dedicated queues.

🧠 Tip: Hooks like environment are executed before any code is checked out, making them ideal for early validation or access control. You can use this to prevent unauthorized users or enforce custom conditions.

Agent and Hooks Overview

Environment and Permissions

Agent Infrastructure

License

See LICENSE.md (MIT)

More examples

Start turning complexity into an advantage

Create an account to get started with a 30-day free trial. No credit card required.

Buildkite Pipelines

Platform

  1. Pipelines
  2. Public pipelines
  3. Test Engine
  4. Package Registries
  5. Mobile Delivery Cloud
  6. Pricing

Hosting options

  1. Self-hosted agents
  2. Mac hosted agents
  3. Linux hosted agents

Resources

  1. Docs
  2. Blog
  3. Changelog
  4. Example pipelines
  5. Plugins
  6. Webinars
  7. Case studies
  8. Events
  9. Migration Services
  10. Comparisons

Company

  1. About
  2. Careers
  3. Press
  4. Security
  5. Brand assets
  6. Contact

Solutions

  1. Replace Jenkins
  2. Workflows for AI/ML
  3. Testing at scale
  4. Monorepo mojo
  5. Bazel orchestration

Legal

  1. Terms of Service
  2. Acceptable Use Policy
  3. Privacy Policy
  4. Subprocessors
  5. Service Level Agreement

Support

  1. System status
  2. Forum
© Buildkite Pty Ltd 2025