To use GitLab CI/CD:
- Ensure you have runners available to run your jobs. Install GitLab Runner and register a runner for your instance, project, or group if you don’t have a runner.
- Create a
.gitlab-ci.ymlfile at the root of your repository. This file is where you define your CI/CD jobs.
In GitLab, runners are agents that run your CI/CD jobs.
You might already have runners available for your project, including shared runners, which are available to all projects in your GitLab instance.
Some points about a runner in GitLab CI/CD
- To view the available runners you can go to Settings then CI/CD and expand Runners.
- As long as you have at least one runner that’s active, with a green circle next to it, you have a runner available to process your jobs.
- If no runners are listed on the Runners page in the UI, you or an administrator must install GitLab Runner and register at least one runner.
- If you are testing CI/CD, you can install GitLab Runner and register runners on your local machine. When your CI/CD jobs run, they run on your local machine.
.gitlab-ci.yml file in GitLab CI/CD
.gitlab-ci.yml file is a YAML file where you configure specific instructions for GitLab CI/CD.
This file contains the structure and order of jobs that the runner should execute and also the decisions the runner should make when specific conditions are encountered.
.gitlab-ci.yml file, you can define:
- The scripts you want to run.
- Other configuration files and templates you want to include.
- Dependencies and caches.
- The commands you want to run in sequence and those you want to run in parallel.
- The location to deploy your application.
- Whether you want to run the scripts automatically or trigger any of them manually.
The scripts are grouped into jobs, and jobs run as part of a larger pipeline. You can group multiple independent jobs into stages that run in a defined order. The CI/CD configuration needs at least one job that is not hidden.
When you add a
.gitlab-ci.yml file to your repository, GitLab detects it and an application called GitLab Runner runs the scripts defined in the jobs.
In this example, the build-code-job job in the build stage runs first. It outputs the Ruby version the job is using, then runs rake to build project files. If this job completes successfully, the two test-code-job jobs in the test stage start in parallel and run tests on the files.
The full pipeline in the example is composed of three jobs, grouped into two stages,
test. Whenever any changes push to any branch in the project the pipeline will run.
GitLab CI/CD not only executes the jobs but also shows you what’s happening during execution, just as you would see in your terminal.
View the status of your pipeline and jobs in GitLab CI/CD
To view your pipeline:
- Go to CI/CD > Pipelines.
A pipeline with three stages should be displayed:
- To view a visual representation of your pipeline, select the pipeline ID.
- To view details of a job, select the job name, for example,
In this blog, we’ve learned about the introduction to GitLab CI/CD in which we learned the GitLab runner, creating the .gitlab-ci.yml file, the stages in the YAML file, and also how we can view the status of your pipeline and jobs.
Hope you enjoyed the blog. Thanks for reading