Using a new 'Workflow' in my config.yaml file

Hi there!

I’m trying to restructure a basic config.YAML file that I made based on a Real Python course into two jobs: build and unittest, and then add those two jobs to a workflow. I’m doing this based on a read-through of the documentation, where I learned about the building blocks of workflows > jobs > steps.

The structure I want to follow is modeled here in the docs.

Here’s the Real Python version, which works well and I’ve integrated into my GitHub checks.

# Python CircleCI 2.0 configuration file
version: 2
jobs:
  build:
    docker:
      - image: circleci/python:3.8

    working_directory: ~/repo

    steps:
      # Step 1: obtain repo from GitHub
      - checkout
      # Step 2: create virtual env and install dependencies
      - run:
          name: install dependencies
          command: |
            python3 -m venv venv
            . venv/bin/activate
            pip install -r requirements.txt
      # Step 3: run linter and tests
      - run:
          name: run tests
          command: |
            . venv/bin/activate
            pytest -v --cov

And here is my restructured version based on the “Sequential Workflow” template in the docs:

# Python CircleCI 2.0 configuration file
version: 2
jobs:
  build:
    docker:
      - image: circleci/python:3.8

    working_directory: ~/repo

    steps:
      # Step 1: obtain repo from GitHub
      - checkout
      # Step 2: create virtual env and install dependencies
      - run:
          name: install dependencies
          command: |
            python3 -m venv venv
            . venv/bin/activate
            pip install -r requirements.txt
  unittest:
    docker:
      - image: circleci/python:3.8
      # Step 3: run linter and tests
    steps :
      - checkout
      - run:
          name: run tests
          command: |
            . venv/bin/activate
            pytest -v --cov
workflows:
  build_and_test:
    jobs:
      - build
      - unittest:
          requires:
            -build

So now I have this restructured version in my project repo’s master branch. When I try to push a test commit, I get this error message in CircleCI:

#!/bin/sh -eo pipefail
# Unsupported or missing workflows config version
# 
# -------
# 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

I’m one day old at this stuff, and quite confused. What have I done wrong?

I’m gonna answer my own question!

So I figured that since each “job” gets its own docker, that they probably aren’t the same one, and that I lose the docker from the build job when that job is finished. Sure enough, I have to re-run the commands to make the virtual environment AND re-install my dependencies.

That fixed it, and now I have another question here: Can I pass the docker from the build job to the test job, since all of the requirements and such are the same?

1 Like

Thank you for posting your answer! This is really helpful :slight_smile:

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