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.
Dependencies
- 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
-
Project Settings > Permissions > API Permissions
- Set the
CIRCLE_TOKEN
environment variable to your API token- You can do this through your project settings:
- Project Settings > Tweaks > Environment Variables
- You can do this through your project settings:
- Add the script to your repository
Usage
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.
Example
deployment:
staging:
branch: master
commands:
- ./do-exclusively --branch master ./deploy.sh