Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Connecting to CircleCI

Give Feedback

This lesson first reveals you how to properly set up the CircleCI config.yml file, which is used to specify the environment and the commands executed in the CircleCI environment. Subsequently, you’ll have a look at the CircleCI web interface to explore the Continuous Integration (CI) tasks, you have defined and which were run after pushing your changes to GitHub.

Note: If you want to learn more about things you can specify in the circleci/config.yml, check out the official documentation.

00:00 Now you’re ready to connect a CircleCI pipeline to your project. Before it knows how to run your build, you need to give it a config file in a specific format.

00:10 Inside your repo, add a .circleci folder.

00:20 CircleCI will look for a config.yml file in here, so go ahead and make that as well. The .yml file uses a serialization language called YAML, which is designed to be pretty human-readable.

00:37 Go ahead and copy and paste in the following code, and we’ll quickly discuss what each line is doing. These first lines are telling CircleCI which Docker container to load up to run your project in. Docker could get its own set of tutorials, so for now, just think of these Docker containers as minimal virtual machines that have just enough resources to run your code. version is selecting the CircleCI API, and then for jobs, you can specify multiple things that you would like to be checked. If you only have one job, you have to call it build. You then tell CircleCI to go to Docker and then load this pre-installed circleci/python3.7 container.

01:18 CircleCI has a bunch of options around running multiple jobs, so if you’re interested, you can take a look at their documentation. For example, you could run your code on multiple versions of Python to check compatibility.

01:30 This working_directory goes and creates a temporary directory on the build server to store all the files. Now, take a look at steps.

01:39 The first thing that it’s going to do is checkout the repo from GitHub, and then it’s going to create the virtual environment and install dependencies. run says it’s going to do a set of steps that you have named install dependencies, and then command is just going to be the actual shell commands to get the environment set up. So it creates a virtual environment, it activates that virtual environment, and then from the requirements.txt file, it installs all the required packages. Once it’s done that, it’s going to go to the next step, where it’s going to run the tests. It’s going to make sure that the environment’s activated and then it’s going to run flake8 and pytest. Okay!

02:19 Now that this is here, using your Git client, add in these changes and then commit them. I’m just going to say something like 'add config files for circleci'.

02:37 push these to GitHub,

02:44 and now it’s time to go to CircleCI. Stopping over real quick, let’s make sure that the repo is updated. You should see everything that you’ve added, and I can tell right away I made a typo in the folder name, so let’s go back and change that.

03:02 Let me rename this, make sure—oops.

03:11 Make sure you spell circle correctly. Let’s go ahead and just add that real quick.

03:32 Push that, let me refresh, there we go. Cool. And head to CircleCI. When you create your account, you can choose to log in with GitHub, which is what I did, and once you’re logged in, you should see this dashboard.

03:48 Right now, I have no projects building on CircleCI, so click on Add Project. And you should see all of your repositories here. CalculatorLibrary is what we want. And now for the setup, because you’ve already added this config.yml file, you can just go right to Start Building. So click on that,

04:21 and this will bring you to a Jobs dashboard. If everything was correct, you should see SUCCESS, and you can actually go through here and see what it was doing.

04:33 First, it was setting up the environment, so there’s a bunch of information there. Here’s where it checked out the code from GitHub,

04:43 and then install your dependencies, and running your tests. You can see the same output that you saw before.

04:53 Now that you’ve connected your project to CircleCI, it’s time to make some changes and see how the pipeline can help you safely modify your code. Thanks for watching.

W Patrick Jones on Dec. 15, 2019

Installing dependencies failed for me because it ran python3 -m venv venv . venv/bin/activate pip install -r requirements.txt all on the same line. I copied your yml file precisely, but it is running all three commands on the same line, causing an unrecognized arguments error. Suggestions?

version: 2
      - image: circleci/python:3.7

    working_directory: ~/repo

      - checkout
      - run:
          name: install dependencies
            python3 -m venv venv
            . venv/bin/activate
            pip install -r requirements.txt

      - run:
          name: run tests
            . venv/bin/activate
            flake8 --exclude=venv* --statistics
            pytest -v --cov=calculator```

Joe Tatusko RP Team on Dec. 17, 2019

Hi Patrick, sorry for the delay, it took a while to reproduce the error on my end. You have the yml file copied almost precisely, but note the pipe operators after “command:”

CircleCI used the “|” symbol to indicate that there will be multiple lines of commands, and then handles them accordingly. Try that out and let me know if it works!

Dave Wilson on Feb. 5, 2020

My build failed due to a line in the requirements, pkg-resources==0.0.0. I looked into this, and apparently it is a known issue with ubuntu:

My build passed when I removed this line from requirements.txt. Thanks for the tutorial!

Joe Tatusko RP Team on Feb. 5, 2020

That’s a great catch, thanks for sharing the fix!

Billa123 on March 24, 2020

My tests are failing while building in CircleCI. Any suggestion?

#!/bin/bash -eo pipefail
./ test
/bin/bash: ./ No such file or directory

Exited with code exit status 127
CircleCI received exit code 127

Billa123 on March 24, 2020

I’m able to solve the problem. Ignore my previous comments.

Joe Tatusko RP Team on March 25, 2020

Hi Naresh, were you able to solve the unit test errors as well?

Glad to know you got it working!

Billa123 on March 25, 2020

Yes, I’m able to solve it.

Nursultan on April 27, 2020

Hey @Billa123,

how did you resolve the issue? I have the same error : / No such file or directory

Nursultan on April 27, 2020

Hi, please disregard my previous comment. I was able to solve the issue.

Howard M Sherman on May 10, 2020

@Billa123, I got that same problem you mentioned in your message on March 24, the “./ no such file or directory” error. How did you fix it?

Ricky White RP Team on May 11, 2020

Hi @Howard. That usually means you are in the wrong directory when you are accessing the script. So you will need to fix the path.

Mike Allan Nillo on June 20, 2020

Hi! I have received a build error: No configuration was found in your project. I run the first build while having a typo in folder, I think it has something to do with cache. How can I solve it?

Become a Member to join the conversation.