Different test requirements on different branches

circle.yml

#1

This doesn’t appear possible at the moment, but I would like to have different test commands run only on certain branches. For example we some automated checks before builds go out into production, but we don’t necessarily need that run on each checkin on other branches.

Perhaps this is possible already somehow.


#2

This is what I have done, maybe it helps someone (or maybe someone “corrects” my approach ^^):

gatekeeper.sh

#!/usr/bin/env bash

# Usage: gatekeeper.sh "<command>"
# Executes script if branch is listed below

branches=('master', 'live', '<whichever_branch_you_like>')

for item in "${branches[@]}"; do
    if [[ $CIRCLE_BRANCH == "$item" ]]; then
        eval "$1"
        exit "$?"
    fi
done;

printf "Gatekeeper: SKIPPING as branch $CIRCLE_BRANCH not whitelisted.\n"

circle.yml

jobs:
  build:
    working_directory: ~/deploy
    docker:
      - image: docker:17
    steps:
      [ .. ]
      - type: shell
        name: Run tests on master and live
        command: ./ci/gatekeeper.sh "<command you want to execute (for certain branches)>"

#3