A genteel peek into GitLab CI/CD

My CI engine of choice & experience as a Tester has been Jenkins.

One of the strategic projects in the pipeline at my current client is to adopt GitLab as a solution for SCM,Continuous Testing and potentially Continuous Deployment .

And that project involves porting a Test Framework ( that I was fortunate to lead create) based on Python/Behave/PyTest running on  Jenkins to GitLab

Even though the project is in the pipeline, I thought to flirt with the idea of doing a wee POC to explore GitLab’s CI/CD .

Objective –

As a novice GitLab user, I would like to set up a trivial build pipeline, so that I can run a piece of Python code on every commit 

Approach –

1. Understand how GitLab’s CI/CD architecture works

2. Sign up for GitLab & set up a project

3. Set up a vehicle to execute your code (aka a “runner”)

4. Write instructions to build your pipeline (aka the “.gitlab-ci.yml” file)

5. See the magic happening i.e. output of your Python code being rendered

Step 1 – (A simplistic view of) GitLab’s CI/CD architecture 

To get a pipeline up and running, you need need components to be talking to each other.

  • A GitLab instance to act as a code repo and host of your project
  • A YAML file that has pipeline details like platform to run on, build steps, shell commands etc , and acts as the orchestrator
  • A local or remote machine to check out code & run the instructions in the YAML file

GitLab

Step 2 – Sign up and create a project in GitLab 

SignIn/Register on GitLab here -> https://gitlab.com/users/sign_in

and create a blank project –

Screen Shot 2020-05-02 at 7.35.19 PM.png

 

Step 3 – Configure a runner  

I decided to use my machine ( MAC OS X) as a runner and these are the steps that I took

  1. Install –  https://docs.gitlab.com/runner/install/
  2. Register your runner – This is a critical step, that will make the GitLab instance know about your local runner. https://docs.gitlab.com/runner/register/ . I chose my runner to be a shell, just for the purposes of keeping this a simple exercise. Important to remember the tag for your runner here, as we will use that to call the runner from the YAML file
  3. Enable this runner in your project settings and disable shared runners. Click “expand” on runners in the settings for your project as below and on the next page click “disable shared runners”Screen Shot 2020-05-03 at 11.54.09 AM.png
  4. If everything is set up correctly, you should see your runner being detected in the settings page as follows . Note the tag “smoke” that I used in step 2 above Screen Shot 2020-05-03 at 11.57.22 AM.png

 

Step 4 – Set up build script 

In this step we will add the gitlab-ci.yml file to the project and make it

a) call & run a python file,

b) on the runner that we configured above

  1. Goto your project homepage & click on “set up CI & CD” Screen Shot 2020-05-03 at 1.13.50 PM.png
  2. On the next page you will be presented a web IDE to create the YAML file, I choose one of the many useful templates available fo my  script Screen Shot 2020-05-03 at 1.18.03 PM.png
  3. My pipeline script is very simple, this should be self explainable , note the bit with the “tags” is what calls the runner ! Screen Shot 2020-05-03 at 1.28.04 PM.png
  4. Lastly, add to the project the python file being called in the pipeline scriptScreen Shot 2020-05-03 at 4.41.01 PM.pngScreen Shot 2020-05-03 at 4.37.44 PM.png

 

Step 5 – Trigger the pipeline

The pipeline YAML script gets trigger automatically on every commit or you can goto Pipelines on the left navigation menu and click the “run pipeline” button

Screen Shot 2020-05-03 at 4.44.42 PM.png

Here is what the output looks like running on a bash shell , as you can see the echo output, output for pwd command and the Python file !

Screen Shot 2020-05-03 at 4.48.09 PM

so, there you go we have successfully set up a basic pipeline in GitLab that run a simple python script on a bash shell. I have liked what I have seen of GitLab so far and will explore more

 

 

 

 

Leave a Reply