Add ability to skip entire job if cache key exists

I have several jobs that are prerequisites for other jobs. These jobs are used to set up baseline caches for the all of the following jobs, such as installing/updating dependencies. 99% of the time none of the dependencies have changed, so running the job is not necessary at all. However, there is overhead every time the job is run:

  1. "Spin up environment" can take 30-60s+ as the Docker image cache is not always consistent.

  2. Restoring a large cache can take 10s+

That is 40-70s+ wasted when a simple presence check on the cache would allow the entire job to be skipped.


I suggest adding a skip_if_cache_exists or similar entry to the job configuration. Example:

skip_if_cache_exists: source-v1-{{ .Branch }}-{{ .Revision }}

This would allow the job to be skipped entirely, avoiding any unnecessary overhead of spinning up the container and restoring caches.

  • Guest
  • Apr 7 2020
  • Taking votes
  • Attach files
  • Kelly Setzer commented
    09 Jul 19:21

    A when condition might be a clean implementation for this.

    version: 2.1

    - restore_cache:
    - v2-pods-{{ checksum "Podfile.lock" }}
    - when:
    condition: cache_miss
    - run: echo "Do special cocoapods magic"
    - unless:
    condition: cache_hit
    - run: echo "Party like it's 1999"
  • Christian Mühlbacher commented
    25 Apr 15:42

    Nr.: /bin/bash

    Nr.: /bin/bash

    circleci config pack src > orb.yml

    circleci orb publish orb.yml circleci/gcp-cli@dev:alpha

    rm -rf orb.yml