An Introduction to CircleCI

Prachi Jain
Xebia Engineering Blog
5 min readMay 13, 2020

Continuous integration is a practice that encourages developers to integrate their code into a master branch of a shared repository. Instead of building out features in isolation and integrating them at the end of a development cycle, code is integrated with the shared repository by each developer multiple times.

CircleCI is the continuous integration & delivery platform that helps the development teams to release code rapidly and automate the build, test, and deploy. CircleCI can be configured to run very complex pipelines efficiently with caching, docker layer caching, resource classes and many more. After repositories on GitHub or Bitbucket are authorized and added as a project to circleci.com, every code triggers CircleCI runs jobs. CircleCI also sends an email notification of success or failure after the tests complete.

How to configure a job in CircleCI

Step 1: CREATE A SAMPLE PROJECT IN GITHUB

Step 2: LOGIN USING GITHUB/BITBUCKET

Step 3: SET UP PROJECT ON CIRCLECI

Step 4: IN GITHUB .CIRCLECI/CONFIG.YML FILE SHOULD BE MADE WHICH WILL RUN THE WORKFLOW

CircleCI finds and runs config.yml and interacts with the code to build to orchestrate your build, tests, security scans, approval steps, and deployment. CircleCI believes in the configuration as code hence it is orchestrated through a single file.

version: 2.1
jobs:
build:
docker:
- image: circleci/node:4.8.2 # the primary container, where your job's commands are run
steps:
- checkout # check out the code in the project directory
- run: echo "hello world" # run the `echo` command
workflows:
version: 2
build:
jobs:
- welcome/run
- build

CircleCI’s build servers have already pre-installed languages and build tools such as Java, Gradle, Maven that you need for standard development. With a custom config.yml, one can prepare an environment for your application code dependency.

Primary process that is used in CircleCI to build the code

  1. executor: adjusting the VM to the preferences and requirements it can be machine, docker or and many more related to the OS
  2. checkout: git repo checking out and cloning feature
  3. dependencies: setting up your project’s language-specific dependencies
  4. code: preparing the code for your tests
  5. test: running your tests
  6. deployment: deploying your code to your web servers

Play with CircleCI

CircleCi provides us with various options to make a complex pipeline work smoothly. For instance, circleci provides the option FOR ENVIRONMENT VARIABLES under BUILD SETTING which can help in ease of the putting secrets data to confi.yml file. Similarly, under PERMISSION, there are multiple options like SSH PERMISSION that helps in the integration key between GitHub and CircleCi to check out the repository code. CHECKOUT SSH KEYS which authenticates the identity to the git. API PERMISSION, AWS PERMISSION and JIRA INTEGRATION are also available for integration with their respective services.

Resource classes

Resource classes allow you to configure the CPU and RAM for each task. We have often heard from customers that limiting memory can lead to test failures, slow down the creation process, or maximum use of RAM, which can result in a browser crash. You can use resource classes to select a large container where you need it and a small container where you don’t.

Workflow

Used for orchestrating all jobs. Each workflow consists of the workflow name as a key and a map as a value. A name should be unique within the current config.yml. The top-level keys for the Workflows configuration are version and jobs. Workflow helps in customization of job in any order i.e. sequentially, parallel or in any way chosen.

Workflows basics

  1. WORKFLOWS is known as a set of rules defining how jobs (such as build, test, deploy) are run, giving teams granular control over the process
  2. JOBS is termed as a collection of steps and an execution environment to run them in
  3. STEP is an executable command

Example 1: Single Build

Example 2: Sequential Flow

Example 3: Independent Builds in the same Workflow

Example 4: Hybrid Workflow

We can further filter the job schedule according to the tag or branch that we want to execute i.e. controlling a job when it should run. We can also corn schedule the job or manually approved jobs.

Example: Job scheduled at midnight UTC only on the master branch of build-package job.

workflows:
version: 2
build-package:
triggers:
— schedule:
cron: “0 0 * * *”
filters:
branches:
only:
— master

Conclusion

The examples above are written to provide a start for the areas of functionalities available through CircleCI config. As it provides easy setup and maintenance. It also provides built-in support for Docker, can be debugged using SSH and automates your software builds, tests, and deployments.

--

--