Automating Software Releases with GitLab CI/CD: A Complete Guide

Software developer and CEO at RoyalZSoftware. I build web applications for startups with Ruby on Rails, Angular and React.
In the world of continuous integration and continuous deployment (CI/CD), automating software releases is a critical step in delivering stable, high-quality code to users. GitLab provides a powerful and flexible system for managing releases, making it easy to integrate this process into your CI/CD pipelines. This guide will walk you through the process of creating automated releases in GitLab CI/CD, enabling smoother deployments and improving efficiency.
What Are Releases in GitLab?
A release in GitLab is a snapshot of your project’s source code at a particular point in time, often associated with specific versions of your software. Releases typically include:
A tag, which marks a specific commit in your repository as a version (e.g.,
v1.0.0).Release notes, which describe the changes in this release.
Any associated artifacts or files, such as compiled binaries or documentation, that are part of the release.
GitLab releases are directly tied to Git tags, and they are often used to publish software to end-users, deploy applications to production environments, or archive stable versions for future reference.
Why Automate Releases in GitLab CI/CD?
Manually creating releases can be time-consuming and prone to errors. Automating releases through GitLab CI/CD has several benefits:
Consistency: Ensures that every release is created following the same process.
Efficiency: Saves time by eliminating manual steps, allowing releases to happen faster.
Reliability: Reduces the risk of human error by automating the tagging and release creation process.
Traceability: Automatically attaches release notes and artifacts to specific tags, making it easy to track the history of your project’s versions.
Step-by-Step Guide: Creating Releases in GitLab CI/CD
Let’s walk through how to create automated releases using GitLab CI/CD pipelines.
1. Set Up Your GitLab CI/CD Pipeline
First, ensure that you have a basic CI/CD pipeline in place by creating or updating your .gitlab-ci.yml file. This file defines the steps (or jobs) that GitLab will run to build, test, and deploy your code.
Here’s a simple pipeline setup to build and test your project:
stages:
- build
- test
build_job:
stage: build
script:
- echo "Building the project..."
- ./build.sh
test_job:
stage: test
script:
- echo "Running tests..."
- ./run_tests.sh
This pipeline builds your project and runs tests, preparing your code for deployment.
2. Define a Job to Tag and Create a Release
To automate the release process, we’ll add a new job to the pipeline to:
Create a Git tag.
Generate release notes.
Publish a release in GitLab.
We’ll use the release keyword, which is a built-in GitLab feature that automates the release creation process. The job will execute when triggered by a new Git tag.
stages:
- build
- test
- release
release_job:
stage: release
script:
- echo "Creating a new release..."
rules:
- if: '$CI_COMMIT_TAG'
release:
tag_name: '$CI_COMMIT_TAG'
name: 'Release $CI_COMMIT_TAG'
description: 'Release notes for version $CI_COMMIT_TAG'
assets:
links:
- name: "Download Project"
url: "https://gitlab.com/your_project/-/archive/$CI_COMMIT_TAG/your_project-$CI_COMMIT_TAG.zip"
Explanation:
rules: The job will only run if a Git tag exists for the commit (
$CI_COMMIT_TAG). This prevents the job from running on every commit.release: This keyword defines the release metadata:
tag_name: The tag that corresponds to the release.name: The name of the release, which in this case dynamically uses the tag name.description: Release notes describing what’s included in the release.assets: You can also include download links, such as a zip file of the project.
3. Create a Git Tag to Trigger the Release
To trigger the release pipeline, you’ll need to create a Git tag. This can be done either through the GitLab web interface or using Git commands.
Here’s how you can create a tag from the command line:
$ git tag v1.0.0
$ git push origin v1.0.0
This will push the tag v1.0.0 to the remote GitLab repository. Once the tag is pushed, GitLab CI/CD will automatically trigger the release job based on the rules defined in the .gitlab-ci.yml file.
4. Check the Release in GitLab
Once the release job has completed successfully, you can view the release in the Releases section of your GitLab project. This section will display all the releases along with their associated tags, notes, and downloadable assets.
To view the release:
Go to your GitLab project page.
Navigate to Repository -> Tags or Deployments -> Releases.
You should see your new release with the corresponding tag name, description, and download links.

