Trigger pipeline on branch deletion

Hi, fellow Buildkiters. First of all thanks for your great work, Buildkite is indeed the best CI system I ever used! :+1:

Recently I bumped into a missing feature that might be interesting. We use GitHub integration and GitHub allows us to set up a trigger on Branch or tag deletion. Meanwhile, there’s no such event to allow on the Buildkite side.
An example use case for this is dropping a per-branch environment on branch deletion. We collect quite a bit of environments during the week in the cloud and they :money_with_wings: while not deleted.
I can think of various workarounds for this, but could you advise me on how to implement it with minimum pain?

I found an issue How to trigger a build step for branch deletion · Issue #739 · buildkite/agent · GitHub, but there’s no solution there, unfortunately.

The ideal situation we would like to have is very simple:

  • Branch deleted in GitHub repo
  • GitHub sends webhook to Buildkite
  • Buildkite triggers the pipeline (which deletes the environment, yada yada)
  • Profit! :rocket:

Thank you in advance.

Hi @brzm!

Welcome to the community! and thank you for your warm words! :blush:

Really interesting suggestion! But unfortunately, we don’t support triggering builds on brunch deletion or PR closed. We try to cover the common cases with our webhook integration, and we typically optimize Buildkite’s GitHub webhook integration for triggering builds on code.

What we’d suggest you instead, and which I think might be both more resilient and more powerful, is setting up a small GitHub Action which responds to these particular events — label added, and pull request closed — and either trigger a Buildkite build via our API, or does the setup or teardown directly. We’ve seen customers do things like this when they have very specific workflow requirements around which actions they want to respond to in particular repos with particular conditions, beyond what we offer with webhooks.

https://github.com/buildkite/trigger-pipeline-action
https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request

Hope this could help you!

Cheers!
Paula

1 Like

Thanks for the help, @paula. We’ll use your advice.
Have a nice one!

1 Like