Getting started with CircleCI

Godlin Hilda J
featurepreneur
Published in
4 min readMay 25, 2021

CircleCI is a modern continuous integration and continuous delivery (CI/CD) platform. The CircleCI Enterprise solution is install able inside your private cloud or data center and is free to try for a limited time. CircleCI automates build, test, and deployment of software.

CI (Continuous Integration) is the practice of testing each change done to your codebase automatically and as early as possible.

CD (Continuous Deployment) follows the testing that happens during Continuous Integration and pushes changes to a staging or production system.

As we now have some clue about CircleCI, let’s create a small python app and set up CircleCI in it to build and test the code whenever our codebase changes.

Create a new folder “CircleCI” and within the newly created folder, create a python file named “app.py”

def Even(a):
if(a%2 == 0):
return True
def Hello():
print("Hello World")
if __name__ == "__main__":
Hello()

Now, we can create a file to test our main file. Create a file named “test.py”

from app import Evendef Test():
assert Even(4) == True
print("Test passed")
if __name__ == "__main__":
Test()

Let us now create a new repo at GitHub and push our code.

Github repo link for the above code — https://github.com/Hilda24/CircleCI

We can now create a config file to setup CircleCI in our project

Create a folder called .circleci and within this folder create a config file config.yml

CircleCI has jobs and workflows. Here we have two jobs — build and test . We also have one workflow build_and_test

For build , we are gonna run our main file which is app.py and for the test , we are running test.py

After creating our config file, We should now push the config file to our repo in GitHub.

Then go to CircleCI.com. If you are not logged in, log in using GitHub. On the sidebar present on the left, Select Projects

On the right, you will see all your repositories displayed. From those, select our newly created CircleCI repo and click on Set Up Project

Next, you will see that CircleCI will ask the type of our project so that it can create a sample config.yml file. Since we have already created a config file, we can go ahead and skip this step.

Click on Use Existing Config

Then, select Start Building

After this, you will see our code is working fine as it passes all our test.

CircleCI is also very helpful to debug your code in case your test fails and you have errors in the code. To check this out, let us change the code so that our code purposefully fails the test.

In test.py make the following changes.

from app import Evendef Test():
assert Even(4) == False #This test will fail as 4 is Even
print("Test passed")
if __name__ == "__main__":
Test()

Now, let us push our newly updated code. Once you push the code, you will notice that CircleCI will start running our repo.

Here you can see our build job is executed successfully as our app.py doesn’t have any errors. Whereas our test.py has an error which led the test job to fail.

We can get more information about why the job failed by clicking on it. In our case, we will click on test

We can now see why we test failed in more detail.

We have seen how to set up CircleCI with a simple python application. Hope you found this article useful!

Keep Exploring!!!

--

--