Serializing Deployments



This is a simple helper script to ensure that a certain action happens once at a time on a CircleCI project. It is a higher-order command like sudo, so you can wrap whatever other commands you want with it.


  • You will need to use either a user or project API token for this to work.
    • You can create a user API token here.
    • You can create a project API token in your project settings.
      • Project Settings > Permissions > API Permissions
        • Note: Make sure you create your token with “All” permissions
  • Set the CIRCLE_TOKEN environment variable to your API token
    • You can do this through your project settings:
      • Project Settings > Tweaks > Environment Variables
  • Add the script to your repository


do-exclusively --branch <somebranch> --tag <sometag> echo "whatever commands I want" The branch and tag arguments are both optional and limit the scope of the command and its lock to a given branch name or builds whose commit message contains a certain commit message. If neither option is used, the wrapped command will run on every build of the project and will wait for any other builds of the project to finish before running.


    branch: master
      - ./do-exclusively --branch master ./

Prevent Concurrent Builds of a Branch
Serialize workflow jobs
Native locking with custom scopes?