Defining and using parameter-less commands

21
#1

Hello,

I’m struggling to set up and use a bunch of shares steps without parameters:
Here are some snippets of my config

version: 2.1

commands:
  initialize-builds:
    name: "Initalizes builds"
    steps:
      - restore_cache:
          name : Restore NPM Cache
          keys:
            - npm-cache-{{ checksum "package.json" }}-{{ .Branch }}
            - npm-cache-{{ checksum "package.json" }}
            - npm-cache-
      - restore_cache:
          name : Restore Yarn Cache
          keys:
            - yarn-cache-{{ checksum "yarn.lock" }}
            - yarn-cache-

jobs:
  test:
    resource_class: medium+
    docker:
      - image: circleci/node:8.15.1-jessie
    steps:
      - checkout
      - initialize-builds

when I try to use this configuration, circle-ci complains with

# ERROR IN CONFIG FILE:
# [#/commands/initialize-builds] 0 subschemas matched instead of one
# 1. [#/commands/initialize-builds] extraneous key [name] is not permitted
# |   Permitted keys:
# |     - description
# |     - parameters
# |     - steps
# |   Passed keys:
# |     - name
# |     - steps
# 2. [#/commands/initialize-builds] expected type: String, found: Mapping
# |   Command may be a string reference to another command
#2

Actually I can’t get this to work with parameters either

#3

What happens if you remove the name declaration from the command?

#4

Same happens…

I’m testing this locally now using

circleci config process .circleci/config.yml >.circleci/configv2.yml
circleci local execute --job test -c .circleci/configv2.yml 

since 2.1 configs aren’t supported by the cli tool and it’s chugging along nicely. Will push it next and verify that it still fails.

It feels like I’m just not picking up the 2.1 features when I try to build but I can’t see any switch to enable it. When was 2.1 released? (I’m new to CircleCI).

#5

Not sure what I did but now it works. Go figure.

Here’s the config now:

restore-npm: &restore-npm
  restore_cache:
    name : Restore NPM Cache
    keys:
      - npm-cache-{{ checksum "package.json" }}-{{ .Branch }}
      - npm-cache-{{ checksum "package.json" }}
      - npm-cache-

restore-yarn: &restore-yarn
  restore_cache:
    name : Restore Yarn Cache
    keys:
      - yarn-cache-{{ checksum "yarn.lock" }}
      - yarn-cache-

restore-meteor-packages: &restore-meteor-packages
  restore_cache:
    name: Restore Meteor Package Cache
    keys:
      - packages-cache-{{ checksum ".meteor/versions" }}
      - packages-cache-

restore-typescript: &restore-typescript
  restore_cache:
    name: Restore Typescript Cache
    keys:
      - typescript-cache-{{ .Branch }}
      - typescript-cache-

commands:
  setup:
    steps:
      - checkout
      - *restore-npm
      - *restore-yarn
      - *restore-meteor-packages
      - *restore-typescript


jobs:
  test:
    resource_class: medium+
    docker:
      - image: circleci/node:8.15.1-jessie
    steps:
      - setup
      - run:

... etc