Buildkite-agent command to signal it should stop after this job

We’re working on a migrating some of our build tooling, and some of our testing has the potential to leave build caches on an agent in an unclean state.

It would be useful to have a command we could issue to the buildkite agent from within the job to tell it that it should stop after the current job completes, so that it doesn’t then pick up a non-migration job and mis-build something.

Hey @richardstephens, this is a great question.

Without knowing more about the particular use case and what you’ve tried so far its a bit tricky to come up with a solid recommendation, but I think there are a few different ways you could go about doing this. The first things that come to mind are:

Job Lifecycle Hooks to manage things like post-job cleanup, etc.

Conditionals in steps may be a good way to control what jobs are run and when they are run.

You could also configure your agents to run single jobs but this may be overkill/not quite what you’re looking for.

Let me know if those options give you some ideas or if you have some more specific use cases or examples you could share that could help find some more suggestions!



Hi @richardstephens I think you might be able to send the SIGTERM signal to the agent currently running which will let it finish its current job and then terminate.

The docs on how the agent handles signals are at The Buildkite Agent v3 | Buildkite Documentation.

And as an example of how the agent can be instructed to shutdown gracefully, check out how our k8s helm chart deployment spec: charts/deployment.yaml at master · buildkite/charts · GitHub
kill -s SIGTERM $(/bin/pidof buildkite-agent)

Hope that helps :+1: