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 .
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
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
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 –
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
- Install – https://docs.gitlab.com/runner/install/
- 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
- 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”
- 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
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
- Goto your project homepage & click on “set up CI & CD”
- 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
- My pipeline script is very simple, this should be self explainable , note the bit with the “tags” is what calls the runner !
- Lastly, add to the project the python file being called in the pipeline script
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
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 !
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