After-exit hook support?

Use Case

I need to clean up a bare metal (non-virtualized) agent after a build completes, but before the agent returns to the pool as available. Currently, I can only clean up at the beginning of each build, which adds extra waiting time to the CI process.

Proposed Solution

An ‘after-exit’ hook that runs after a job finishes but before the agent becomes available again. This would allow for:

  1. More responsive CI: When one build finishes, the agent could enter a “cleanup” state while other available agents take new requests immediately.
  2. Time savings: This approach could save 1-2 minutes of waiting time, especially when the build queue is semi-full.
  3. Efficient resource management: Cleanup happens “off the clock”, not impacting build times.

Current Limitations

If I understand correctly, the existing hooks (like ‘pre-exit’ or ‘pre-bootstrap’) would delay the current job or the next job, which isn’t ideal for maintaining CI responsiveness.

Request

Could the Buildkite team consider implementing an ‘after-exit’ agent hook? This would run after a job completes but before the agent returns to the available pool.

Thank you for considering this feature request in advance. If such feature already exists, I’d be grateful for any information.

Hi @noomorph :wave:,

This is Suma from Buildkite support team. Thank you for reaching out to us with your question.

When you say “Need to clean up a bare metal agent after build completes”, is this a Buildkite agent ? If so you want that agent to stop or you want the bare metal instance on which the agent is running to be shutdown ?

Is it the same agent on bare metal instance that is handling the all the steps for that build ?

Thanks,
Suma

when you say current limitation with pre-exit hook is it would delay the current jo