Continues integration, continues delivery and continues deployment (CI/CD)

Jayamal Jayamaha
6 min readJan 8, 2020

I did my internship as a trainee software engineer at CodeGen International (pvt) ltd which is a leading and innovating software company in SriLanka. In that internship period, I learned many technologies, strategies as well as best practices related to software developing. One of a great thing that I learned is the CI/CD

CI/CD is technique that uses in DevOps which is help to maintain a good quality code-base in continues development environment to developers. In CodeGen I was assigned to CodeGen annotator project, and in that project I was assigned to develop a CI/CD pipeline using gitlab. In following sections I am going to discuss about CI/CD and aslo my experience about that.

What is CI/CD

Imagine you and your team have assigned to a software project. then your team members develops the code, test the code and push it into git. Then add some modifications to code and again test the code and again push it into git repo. The problem is this method is this process has to be done on every single change of the code base. Also your team has to face many errors because every team member is contributing to same git repo. So there will be merge errors, compatible errors etc. As a solution for that CI/CD process one of best approach to minimize that inconvenience situations.

Basically CI/CD involves continuously building, testing, and deploying code changes at every small iteration, reducing the chance of developing new code based on bugged or failed previous versions. There are three parts in CI/CD and they are

Continues Integration

Continues Development

Continues Deployment

Above three parts are described step by step in below

Continues Integration

There are multiple contributors as well as multiple teams like QA team, Dev team, etc. in a software project and they all contribute to that relevant software project. If we didn’t use a right CI environment, developers must manually test the code and inform about it to team members as well as other teams and then merge it to the master. So there may be errors because of communication overhead. which adds unnecessary cost to the project. This causes slower code releases with higher rates of failure. This is why we need continues integration process to our project.

Continues Development

In agile process there is a iterative method for the software development. In agile process we develop the code, then test it, and shows to the client, then when client verified that we deploy that and go build next feature or if client request changes we go to build that changes. This same process we use in continues development process but with a efficient manner. Developers use ongoing development with smaller incremental changes that can be quickly deployed, and easily withdrawn in case problems arise. So developers can release as soon as they developed and go to next development process and when user reported a bug, developers can work on that release a patch.

Continues Deployment

After development process of software, it has to be deployed to production environment as a usable product to users. If we do this deployment process manually we have to test the code manually and then have to validate code manually and finally have to deploy to production environment. So using continues deployment in CI/CD methodology we can automate above process.

GitLab CI/CD

Gitlab gives us the ability to use CI/CD in it’s own platform, so now I am going to demonstrate the CI/CD process and pipelines using this GItlab CI/CD platform.

You need to put you project to a gitlab repo in-order to use gitlab CI/CD functionality. The main file that use to instantiate the CI/CD to your project is .gitlab-ci.yml file. It is a configuration file that use to write all the configurations, scripts, jobs and pipelines together. There some terms and words related to this yml file.

Pipeline

Pipeline is the top level component in CI/CD process. under the pipeline there are jobs that defined what to run and stages that defines when and how to run those jobs.

One pipeline with four jobs

Stages

Stages are included inside to the pipeline. Stages divide the pipeline to several parts and run them when the need to run. Basically Stages define when and how to run

ex: in above image

build - this stage is the first one that runs in pipeline.

test - this stage runs after the build stage and so on

Jobs

Jobs are define inside a stage. One stage can have multiple jobs and they can be run parallel to each other. in above image there are 2 jobs in test stage and both jobs are to run test cases. We have to run multiple test cases to test our products and also if we need to deploy that to more than one environments we can also use multiple jobs to staging and production stages as well.

Script

Script is a normal shell or cmd script that runs in the environment. bassically it is a command that we use to run, build or deploy our project. Scripts are configured inside a job

Image

We use image to pull and define the docker image and configure our docker container environment.

Now we have a basic understanding about these terms that we usually use to write a basic .yml file. Now we look how to write a basic .yml file in order to configure CI/CD process to our project.

Basic .gitlab-ci.yml file

Basic .gitlab-ci.yml file

Like above sample .yml file first we have to define stages that we are going to use and that stages define under stages keyword. after that we define each job and inside each job we define the stage that it belong to and also the script that we are going to run in this job using stage and script key words. we can also define the docker image in a default job if we need to use docker container like following image using image key word

using the docker image

Also we can define only and except keywords inside a job. we use only keyword when we need to run this particular job to specific branch or tag only and we use except keyword to run a particular job to all the branches or tags except the specific branch or tag.

only and except key word

Also we can use before_script and after_script keywords to configure the configurations before run a job or all the jobs or after running the job or all the jobs.

before_script and after_script

This is a basic understanding an configuration of GitLab CI/CD and .yml file. We can write complex .gitlab-ci.yml files if we need using more usefull keywords. also we can configure this CI/CD to more complex projects. I am referring some usefull links here if you like to learn more and have a idea to write complex .yml files.

References

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Jayamal Jayamaha
Jayamal Jayamaha

Written by Jayamal Jayamaha

A boy who loves to explore all the sciences

No responses yet

Write a response