Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger a GitLab CI/CD Pipeline when cutting a new Release?

I'm in the process of migrating my projects from GitHub.com to a self-hosted GitLab CE instance. I had previously set up a GitHub Actions pipeline to publish the application when a new release was cut from a tag. That is, when I went to github.com/<organization>/<project>/tags and edited a tag to publish a release, the following *-workflow.yml script snippet would trigger my desired action:

on:
  release:
    types: [created]

What is the equivalent of that on GitLab CI/CD (.gitlab-ci.yml)? I searched all over the GitLab docs and auxiliary websites like gitlab.reddit.com and Stack Overflow, but couldn't find any way to do that. To be clear, the steps for converting a tag into a bona-fide release in GitLab are as follows:

  1. Go to <GitLab CE>/<group>/<project>/-/releases/new
  2. "Create from" any tag in the list
  3. Fill out the details
  4. Click on the "Create release" button

I'd like GitLab to execute my script immediately upon step 4 above.

like image 989
ilyakam Avatar asked Jan 17 '26 03:01

ilyakam


1 Answers

I'm not sure if Gitlab has a similar feature, or at least I couldn't find anything in the documentation.

A workaround could be creating a release automatically in the CI pipeline after creating a tag. So whenever a tag is created from a specific branch, the CI pipeline will create a release. You can also control the creation of the Release using the $CI_COMMIT_TAG value.

release:
  stage: release
  script:
    - echo "Create release when a tag is created"
  rules:
    - if: '$CI_COMMIT_TAG' # Any tag is created
    - if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+\-release/' # A specific tag with 'vX.Y.Z-release' pattern is created
  release:
    name: 'My awesome release'
    tag_name: '$CI_COMMIT_TAG'

For more information about creating a new Release using the CI pipeline you can read this page from the documentation:

Create release from GitLab CI

like image 66
Reza Ebrahimpour Avatar answered Jan 19 '26 18:01

Reza Ebrahimpour