Search code examples
continuous-integrationcirclecicircleci-2.0circleci-workflows

CircleCI version 2.1 - "Cannot find a definition for command named 'restore-cache'"


I'm currently attempting to use the commands feature available in CircleCI version 2.1, so that I can reuse some common commands. I'm testing using the CLI command:

circleci config process ./.circleci/config.latest.yaml > ./.circleci/config.yml

But I recieve the following error:

Error: Error calling workflow: 'main'
Error calling job: 'build'
Error calling command: 'build_source'
Cannot find a definition for command named restore-cache

It seems that restore-cache works just fine in a straight-up version 2 config file, but when I try and process a 2.1 file using process it kicks up a fuss.

Below is an edited version of my config.yaml file which should hopefully be of some use. Please let me know if there is any additional information that would be useful.

version: 2.1

defaults: &defaults
  /**
   *  Unimportant stuff
   */

aliases:
  - &restore-root-cache
    keys:
      - v1-deps-{{ .Branch }}-{{ checksum "package.json" }}
      - v1-deps-{{ .Branch }}
      - v1-deps

commands:
  build_source:
    description: 'Installs dependencies, then builds src, builds documentation, and runs tests'
    steps:
      - restore-cache: *restore-root-cache
      - other-commands...

jobs:
  build:
    <<: *defaults
    steps:
      - checkout
      - build_source

workflows:
  version: 2.1
  main:
    jobs:
      - build:
          filters:
            branches:
              ignore: develop

Solution

  • The command is restore_cache (with an underscore), not restore-cache (with a dash) https://circleci.com/docs/2.0/configuration-reference/#restore_cache

    It should work in commands.