Skip to content

An example pipeline demonstrating how to use agent hooks to control which teams may run pipelines on specific agents.

License

Notifications You must be signed in to change notification settings

buildkite/agent-hooks-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Buildkite Agent Hooks Example

Build status Add to Buildkite

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, or try it yourself:

Add to Buildkite

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.

Related Documentation

Agent and Hooks Overview

Environment and Permissions

Agent Infrastructure

License

See LICENSE.md (MIT)

About

An example pipeline demonstrating how to use agent hooks to control which teams may run pipelines on specific agents.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •  

Languages