Run bash command in additional step alongside orb

I am using an orb and am trying to add an step that simply runs a bash script but I keep getting the error Error calling workflow: 'all' Cannot find a definition for job named cool-down

version: 2.1

orbs:
  node-service: phdv/node-service@2.1.0
  terraform: phdv/terraform@2.0.3

parameters:
  terraform_version:
    type: string
    default: 0.12.24

executors:
  node:
    docker:
      - image: circleci/node:12
        auth:
          username: $DOCKER_HUB_USERNAME
          password: $DOCKER_HUB_PASSWORD

workflows:
  version: 2
  all:
    jobs:
      - node-service/install_yarn_deps:
          name: install
          executor: node
          context:
            - phdv-aws
            - phdv-docker-hub-creds
      - node-service/run_script:
          name: lint
          executor: node
          context:
            - phdv-docker-hub-creds
          package_manager: yarn
          script_name: lint
          requires:
            - install
      - node-service/run_script:
          name: test
          executor: node
          context:
            - phdv-docker-hub-creds
          package_manager: yarn
          script_name: test
          requires:
            - install
      - node-service/run_script:
          name: check
          executor: node
          context:
            - phdv-docker-hub-creds
          package_manager: yarn
          script_name: typecheck
          requires:
            - install
      - node-service/run_script:
          name: audit
          executor: node
          context:
            - phdv-docker-hub-creds
          package_manager: yarn
          script_name: audit
          requires:
            - install
      - node-service/run_script:
          name: build
          executor: node
          context:
            - phdv-docker-hub-creds
          package_manager: yarn
          script_name: build
          persist_to_workspace: true
          requires:
            - lint
            - test
            - check
            - audit
      - node-service/run_script:
          name: package
          executor: node
          context:
            - phdv-docker-hub-creds
          package_manager: yarn
          script_name: package
          persist_to_workspace: true
          requires:
            - build
      - terraform/init_and_plan:
          name: terraform_plan
          context:
            - phdv-aws
            - phdv-docker-hub-creds
          terraform_version: <<pipeline.parameters.terraform_version>>
          working_directory: ~/project/infra
          persist_to_workspace_filepath_prefix: infra/
          requires:
            - package
      - terraform/init_and_apply:
          name: terraform_apply
          context:
            - phdv-aws
            - phdv-docker-hub-creds
          terraform_version: <<pipeline.parameters.terraform_version>>
          working_directory: ~/project/infra
          requires:
            - terraform_plan
      - cool-down:
          machine: true
          steps:
            - run:
                name: stopwatch
                command: sleep 100; exit 1
          requires:
            - terraform_apply

Hello @farhad-taran, and welcome to the CircleCI Discuss community!

You’re trying to call a job that hasn’t been declared hence the error you’re getting.

The declaration of a given job can’t be done within the workflow itself. It has to be done ahead of that, within a jobs map.

For reference, you can find sample config.yml in our documentation.

Also note that you can validate your configuration file locally without having to trigger a build; this can be done with the CircleCI CLI

With the above said, I suggest the following configuration:

version: 2.1

orbs:
  node-service: phdv/node-service@2.1.0
  terraform: phdv/terraform@2.0.3

parameters:
  terraform_version:
    type: string
    default: 0.12.24

executors:
  node:
    docker:
      - image: circleci/node:12
        auth:
          username: $DOCKER_HUB_USERNAME
          password: $DOCKER_HUB_PASSWORD

jobs:
  cool-down
    machine: true
    steps:
      - run:
          name: stopwatch
          command: sleep 100; exit 1


workflows:
  version: 2
  all:
    jobs:
      - node-service/install_yarn_deps:
          name: install
          executor: node
          context:
            - phdv-aws
            - phdv-docker-hub-creds
      - node-service/run_script:
          name: lint
          executor: node
          context:
            - phdv-docker-hub-creds
          package_manager: yarn
          script_name: lint
          requires:
            - install
      - node-service/run_script:
          name: test
          executor: node
          context:
            - phdv-docker-hub-creds
          package_manager: yarn
          script_name: test
          requires:
            - install
      - node-service/run_script:
          name: check
          executor: node
          context:
            - phdv-docker-hub-creds
          package_manager: yarn
          script_name: typecheck
          requires:
            - install
      - node-service/run_script:
          name: audit
          executor: node
          context:
            - phdv-docker-hub-creds
          package_manager: yarn
          script_name: audit
          requires:
            - install
      - node-service/run_script:
          name: build
          executor: node
          context:
            - phdv-docker-hub-creds
          package_manager: yarn
          script_name: build
          persist_to_workspace: true
          requires:
            - lint
            - test
            - check
            - audit
      - node-service/run_script:
          name: package
          executor: node
          context:
            - phdv-docker-hub-creds
          package_manager: yarn
          script_name: package
          persist_to_workspace: true
          requires:
            - build
      - terraform/init_and_plan:
          name: terraform_plan
          context:
            - phdv-aws
            - phdv-docker-hub-creds
          terraform_version: <<pipeline.parameters.terraform_version>>
          working_directory: ~/project/infra
          persist_to_workspace_filepath_prefix: infra/
          requires:
            - package
      - terraform/init_and_apply:
          name: terraform_apply
          context:
            - phdv-aws
            - phdv-docker-hub-creds
          terraform_version: <<pipeline.parameters.terraform_version>>
          working_directory: ~/project/infra
          requires:
            - terraform_plan
      - cool-down:
          requires:
            - terraform_apply

 
Let me know if you have any question.

1 Like

thanks for your reply but it does not work and fails with :
#!/bin/sh -eo pipefail
# Unable to parse YAML
# mapping values are not allowed here
# in ‘string’, line 22, column 10:
# machine: true
# ^
#
# -------
# Warning: This configuration was auto-generated to show you the message above.
# Don’t rerun this job. Rerunning will have no effect.
false

Exited with code exit status 1
CircleCI received exit code 1

Apologies, @farhad-taran! I just noticed I forgot the : after the job name in the job declaration.

It should be:

jobs:
  cool-down:
    machine: true
    steps:
      - run:
          name: stopwatch
          command: sleep 100; exit 1

I was advising you to use the validation feature of the CircleCI CLI but I obviously didn’t follow my own advice here. How ironic! :grin:

Thanks, I managed to fix that but maybe you can help with the following:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.