Error when using a workflow

Hi all!

First time using Circle CI having migrated from Travis CI, Jenkins and GitLab CI.

So far so good, other than one minor problem that I can’t seem to fix. I am getting the error:

requires job “build” but “build” is not part of this workflow.

I have done some research on Stackoverflow and Discuss, most of the issues state indentation however I believe that the indentation in the yaml is correct.

version: 2
jobs:
  test:
    working_directory: ~/crm-dashboard
    docker:
      - image: circleci/node:12-browsers
    steps:
      - checkout
      - restore_cache:
          key: crm-dashboard-{{ .Branch }}-{{ checksum "package-lock.json" }}
      - run: npm install
      - save_cache:
          key: crm-dashboard-{{ .Branch }}-{{ checksum "package-lock.json" }}
          paths:
            - "node_modules"
      - run: xvfb-run -a npm run test --no-watch --no-progress --browsers=ChromeHeadlessCI
      - run: xvfb-run -a npm run e2e --configuration=protractor-ci.conf.js
  build:
    steps:
      - checkout
      - run:
        name: Set Docker Tag
        command: |
          export TAG=if [$CIRCLE_BRANCH=="master"] then "latest" else $CIRCLE_BRANCH fi
          echo $TAG
      - setup_remote_docker
      - run:
        name: Build Docker Image
        command: docker build . -t crm-dashboard:$TAG -f ./docker/Dockerfile --build-arg CONFIGURATION=$CIRCLE_BRANCH
  publish:
    steps:
      - checkout
      - setup_remote_docker
      - run:
          name: Publish Docker Images to Docker Hub
          command: |
            echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
            docker push crm-dashboard:latest

workflows:
  version: 2
  build_and_publish:
    jobs:
      - publish:
          requires:
            - build
          filters:
            branches:
              only: master

any help at all would be appreciated on this. Thanks in advance.

I suspect you need to define build as a job in this workflow (at the same level as publish). The requires device helps you specify the order, but it does not define it as well. This can just be:

- build

Of course you can add filters/requires to this job if you need to:

-build:
    (additional config)