CloudBuild: Open-sourcing Cancelot

Pavlos-Petros Tournaris
Jul 23 · 2 min read
Image taken from:

CloudBuild is a CI/CD offered by Google. At Workable’s Mobile department we made a proof of concept to check if CloudBuild fits our needs in order to be used for artifact (APK) building.

A complex project requires a lot of custom configuration in order to properly set it up and we were able to find most of them in the great CloudBuilders community repo.

Cancelling a running build

CloudBuild builds though come at a cost and depending on your budget and the machine type you use. So having builds run for multiple commits that are pushed on a branch, means a bigger cost on your monthly bill.

As you might have guessed this is something that would not work in case multiple members of our team were working on the same branch and pushing commits with a high frequency.

We need to find a solution that would let us cancel any previously running builds in favor of the new ones.

Entering Cancelot

Cancelot is the name of the Builder we built for the purpose described above. Initially our team had named it “Ralph” from the movie “Wreck-it Ralph”, but Twitter is so resourceful and came up with the name “Cancelot”.

Cancelot is added as a buildstep on your CloudBuild YAML file and is responsible to check for any builds that are currently running for the same branch.

It makes use of the CloudBuild Go package in order to fetch the running builds, by filtering with the following criteria:

build_id != "[CURRENT_BUILD_ID]" AND 
source.repo_source.branch_name = "[BRANCH_NAME]" AND
status = "WORKING" AND

After successfully fetching any previously started (& still running builds) it loops through them and cancels them.


Cancelot’s usage and setup is inspired by the CloudBuilders “slackbot” so it is very easy to use it.

  • Deploy the GCR image of Cancelot to your project’s GCR
  • Add Cancelot’s buildstep in your CloudBuild YAML file
- name: '$PROJECT_ID/cancelot'
args: [
'--current_build_id', '$BUILD_ID',
'--branch_name', '$BRANCH_NAME'

Open Source

We wanted to give back to the community, just like we were able to use the great stuff that other members have built. Cancelot currently lives on an open PR in CloudBuilders community repository. You are free to use it at your own will until the PR is either accepted or closed 😄

Pavlos-Petros Tournaris

Written by

Android GDE — Mobile Team Lead @ Workable

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade