What is GitLab? Explore Its Key Features and Uses


GitLab is a web-based DevOps lifecycle tool that provides a Git-repository manager, similar to GitHub, along with wiki, issue-tracking, and continuous integration/continuous deployment and monitoring features, using an open-source license, developed by GitLab Inc.
GitLab is a complete DevOps platform built from the ground up to bring speed, efficiency, and security to the development, operations, and security teams. It allows you to develop, secure, and operate your applications from a single, integrated platform.
GitLab provides the following main features
Version Control: GitLab provides a Git-based version control system for source code management.
Issue Tracking: GitLab provides an issue tracking system to track bugs, tasks, and enhancement requests.
Code Reviews: GitLab provides a web-based code review tool that allows developers to review and comment on code changes.
Continuous Integration/Continuous Deployment (CI/CD): GitLab provides a built-in CI/CD system that automates the testing, building, and deployment of applications.
Container Registry: GitLab provides a container registry for building and deploying Docker containers.
Kubernetes Integration: GitLab provides integration with Kubernetes for managing and deploying containerized applications.
Security Testing: GitLab provides a security testing framework for testing application security vulnerabilities.
Monitoring: GitLab provides monitoring tools for tracking the performance and health of applications.
Wiki: GitLab provides a wiki for documenting projects and providing information to users.
GitLab is available in two versions: Community Edition (CE), which is free and open-source, and Enterprise Edition (EE), which includes additional features and support.
What is the difference between Jenkins and GitLab?
GitLab and Jenkins are both popular tools in software development, but they have different purposes and features.
GitLab is a complete DevOps platform that offers version control, issue tracking, continuous integration and delivery, and more, all in one application. It is a web-based tool that can be hosted on-premises or in the cloud, providing a smooth experience for developers working on a project.
Jenkins, on the other hand, is an open-source automation server that helps developers build, test, and deploy software in a continuous integration and delivery (CI/CD) pipeline. It is a Java-based tool that can be installed on any operating system and has a pluggable architecture, allowing developers to enhance its functionality with plugins.
The key differences between GitLab and Jenkins
Scope: GitLab is a complete DevOps platform that covers the entire software development lifecycle, while Jenkins mainly focuses on automation in the CI/CD pipeline.
Integration: GitLab provides a more seamless experience for developers, with features like version control, issue tracking, and continuous integration and delivery all in one application. Jenkins, however, needs plugins and integrations with other tools to offer similar functionality.
Ease of use: GitLab is known for being easy to use with a user-friendly interface, whereas Jenkins requires more technical knowledge and setup to use effectively.
Scalability: Jenkins is better suited for large organizations and complex projects with high automation needs, while GitLab is ideal for smaller teams and projects.
Licensing: GitLab offers both free and paid versions, while Jenkins is open-source and free to use.
In summary, GitLab is a complete and integrated solution for smaller teams, while Jenkins is a powerful automation tool for large organizations, so the choice between them depends on your organization's specific needs.
How to Use GitLab
Using GitLab involves several steps, including creating a project, cloning the repository, committing changes, and pushing them back to the repository. Here's a basic overview of how to use GitLab:
Create a project: Go to your GitLab instance and create a new project. Choose whether it should be public or private, select a visibility level, and choose a Git repository template.
Clone the repository: Once the project is created, you'll see a "Clone" button on the project's main page. Click this button to copy the Git URL. Open a terminal window and use the git clone command to clone the repository to your local machine.
git clone https://gitlab.com/username/project-name.git
Make changes: Open the cloned repository in your preferred code editor and make changes to the code or other files. When you're ready to commit your changes, save the changes and switch back to the terminal window.
Commit changes: Use the git add command to add the changed files to the staging area.
git add .
- Then use the git commit command to commit the changes.
git commit -m "Commit message"
- Push changes: Use the git push command to push the changes back to the GitLab repository.
git push origin main
Create merge requests: Once you've pushed your changes, you can create a merge request to merge your changes into the main branch. Go to the GitLab project page and click the "New merge request" button. Select the branches you want to merge and provide a description of the changes.
How to create pipeline in GitLab
To create a pipeline in GitLab, you will need to create a .gitlab-ci.yml file in the root directory of your repository. This file will contain the configuration for your pipeline, including the stages, jobs, and scripts that you want to run.
Here is an example .gitlab-ci.yml file that defines a simple pipeline with four stages:
stages:
- build
- test
- push
- deploy
build_job:
stage: build
script:
- echo "Building the project"
test_job:
stage: test
script:
- echo "Running tests"
push_job:
stage: push
script:
- echo "Pushing the project to the repository"
deploy_job:
stage: deploy
script:
- echo "Deploying the project to the production environment"
This pipeline has four jobs: build_job,test_job,push_job and deploy_job:. Each job has a stage defined, and the test_job depends on the build_job to complete successfully.
Once you have created your .gitlab-ci.yml file, you can commit and push it to your GitLab repository. This will trigger the pipeline to run and execute the defined jobs. You can customize your pipeline by adding more jobs, stages, and scripts, and by using advanced features such as caching, artifacts, and variables. To learn more about creating pipelines in GitLab, you can check out the official documentation and tutorials. Note: Make sure to commit and push the .gitlab-ci.yml file before pushing any changes, so that GitLab knows about your pipeline configuration.
What is variables secrets and artifacts in Gitlab
Variables, secrets, and artifacts are three important concepts for customizing and managing your build pipelines in GitLab. Here's a brief explanation of each:
Variables are values that can be used within your GitLab CI/CD pipeline configuration to customize the behavior of your pipeline, such as specifying image names, endpoints, or access keys. You can define variables at different levels, such as the pipeline, job, or script level.
Variables can be defined in the
.gitlab-ci.yml
file or in the GitLab UI. In the.gitlab-ci.yml
file, you can define variables using thevariables
keyword followed by a list of variable definitions in the formatKEY=VALUE
. For example:
variables:
IMAGE_NAME: my-image
ENDPOINT: http://my-endpoint.com
In the GitLab UI, you can define variables by going to the Settings > CI/CD > Variables section of your project and adding a new variable.
Variables can be accessed in your pipeline scripts using the $VARIABLE_NAME
syntax. For example, you can use $IMAGE_NAME
and $ENDPOINT
in your script to reference the values of the corresponding variables.
Variables defined at the pipeline level are available to all jobs in the pipeline. Variables defined at the job level are only available to that job. Variables defined at the script level are only available within the script where they are defined.
GitLab also supports predefined variables that provide information about the pipeline, such as the pipeline ID, the branch or tag being built, or the user who triggered the pipeline. You can find a list of predefined variables in the GitLab documentation.
- Secrets are variables that are encrypted and can only be accessed by GitLab CI/CD jobs. Secrets are useful for storing sensitive information, such as API keys, passwords, or access tokens, and can be defined in the GitLab UI and referenced in your
.gitlab-ci.yml
file. By using secrets, you can keep your sensitive information safe and secure during the build process.
To define a secret in GitLab, go to the Settings > CI/CD > Variables section of your project and add a new variable with the "Protect variable" checkbox selected. This will encrypt the variable and make it only accessible by GitLab CI/CD jobs.
To reference a secret in your .gitlab-ci.yml
file, use the $SECRET_NAME
syntax. For example, if you have a secret named API_KEY
, you can reference it in your script using $API_KEY
.
It is important to note that secrets are only accessible by GitLab CI/CD jobs and cannot be accessed by regular GitLab project members. This helps to ensure that your sensitive information is kept safe and secure.
Using secrets in your pipeline can help you keep your sensitive information secure and protect your project from unauthorized access.
Artifacts are files that are produced during the execution of your pipeline and can be stored for later retrieval, such as when you want to download a binary or log file from a previous run.
Artifacts can be defined and downloaded using the
.gitlab-ci.yml
file or the GitLab UI. To define artifacts in your.gitlab-ci.yml
file, use theartifacts
keyword followed by a list of artifact definitions. Each artifact definition should include the path to the artifact and an optionalexpire_in
value specifying how long the artifact should be retained.
Here is an example of what the artifacts
section of your .gitlab-ci.yml
file might look like:
artifacts:
paths:
- bin/
- logs/
expire_in: 1 week
This will store all files in the bin/
and logs/
directories as artifacts, and will remove them from GitLab's storage after 1 week.
To download artifacts from your pipeline, go to the Jobs > Expand section of a specific pipeline run and click the "Download" button next to the artifact you want to download.
Artifacts are useful for sharing files between different stages of your pipeline or for sharing files with other members of your team. For example, you might use artifacts to share a binary file that is built in one stage of your pipeline and be used in a later stage.
Using artifacts in your pipeline can help you manage and share files more efficiently, and make it easier to troubleshoot and debug your pipeline.
What is Self hosts and SaaS runners
Self-hosted and SaaS (Software as a Service) runners are two types of workers that are used to execute your build jobs in GitLab CI/CD. Here's a brief explanation of each.
**Self-hosted runners: Self-hosted runners are runners that are installed and managed by you on your own infrastructure. This means you have complete control over the hardware, operating system, and software that the runner is running on. You can install self-hosted runners on your own servers, virtual machines, or containers. Self-hosted runners can be used for both public and private projects, and can be shared between multiple projects.
SaaS runners: SaaS (Software as a Service) runners are runners that are provided and managed by GitLab.com as a cloud-based service. SaaS runners are available for public and private projects, and can be used to execute your build jobs in a scalable and on-demand fashion. SaaS runners are billed based on usage, and can be used to execute both simple and complex build jobs.
Both self-hosted and SaaS runners can be used to execute your build jobs, but they have some key differences. Self-hosted runners offer more control over the build environment, while SaaS runners offer more flexibility and scalability. The choice of which type of runner to use depends on your specific needs and requirements.
For example, if you have strict security requirements or need to customize the build environment, self-hosted runners may be the best choice. On the other hand, if you need to scale your build capacity or want to avoid managing the infrastructure, SaaS runners may be a better fit.
In summary, self-hosted and SaaS runners are two types of workers used to execute build jobs in GitLab CI/CD. Self-hosted runners offer more control over the build environment but require you to manage the infrastructure, while SaaS runners offer more flexibility and scalability but are provided as a cloud-based service. The choice of which type of runner to use depends on your specific needs and requirements.
How to Create a Project deployment via CI/CD pipelines in GitLab
Here are the steps to create a project deployment via CI/CD pipelines in GitLab:
Create a new GitLab project or use an existing one
Go to the Settings > CI/CD section of your project and enable the CI/CD feature.
Create a .gitlab-ci.yml file in the root directory of your repository. This file will define the CI/CD pipeline for your project.
Define the different stages of your pipeline in the .gitlab-ci.yml file. In this case, the stages will be build, test, push, and deploy.
Here is an example of what your .gitlab-ci.yml file might look like
stages:
- build
- test
- push
- deploy
variables:
DEPLOY_ENV: "production"
GITLAB_USER_KEY: "this-is-my-secret-key"
build_job:
stage: build
script:
- echo "This $CI_PROJECT_NAME build is done using command <docker build -t tag .>"
tags:
- dev
test_job:
stage: test
script:
- echo "This is testing of out docker build done by $CI_COMMIT_AUTHOR"
- mkdir -p logs
- echo "these are my test results" > logs/app.log
artifacts:
paths:
- logs/
expire_in: 1 week
tags:
- dev
push_job:
stage: push
script:
- echo "this"
- echo "is pushing to docker hub for $DEPLOY_ENV"
tags:
- dev
deploy_job:
stage: deploy
script:
- echo "this"
- echo "is deploying to EC2 instance for $DOCKERHUB_USER"
- echo "this log is from $CI_JOB_STAGE" >> logs/app.log
artifacts:
paths:
- logs/
expire_in: 1 week
tags:
- dev
dev_test_job:
stage: test
script:
- echo "tested for dev using $GITLAB_USER_KEY"
tags:
- dev
prd_test_job:
stage: test
script:
- echo "tested for prd $GITLAB_USER_KEY"
tags:
- dev
Customize the scripts for each job according to your project's needs. For example, in the build_job, you might include commands to compile your code, create a package, or build a Docker image. In the test_job, you might include commands to run unit tests, integration tests, or performance tests. In the push_job, you might include commands to push the built project to a Git repository or a package repository. In the deploy_job, you might include commands to deploy the project to a production server or a cloud environment.
Commit the .gitlab-ci.yml file to your repository and push the changes.
Go back to the Settings > CI/CD section of your project and make sure that your pipeline runs correctly. You can monitor the pipeline's progress in the CI/CD > Pipelines section of your project.
Subscribe to my newsletter
Read articles from Bittu Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Bittu Sharma
Bittu Sharma
Hi, This is Bittu Sharma a DevOps & MLOps Engineer, passionate about emerging technologies. I am excited to apply my knowledge and skills to help the organization deliver the best quality software products. β’ π¦πΌπ³π π¦πΈπΆπΉπΉπ ππ²π'π ππΌπ»π»π²π°π I would love the opportunity to connect and contribute. Feel free to DM me on LinkedIn itself or reach out to me at bittush9534@gmail.com. I look forward to connecting and networking with people in this exciting Tech World.