9

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.

ilyakam
  • 547
  • 4
  • 11

1 Answers1

9

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

Reza Ebrahimpour
  • 814
  • 6
  • 20
  • Thanks for chiming in, Reza. That's a good workaround which would be ideal in situations where _every_ matching tag needs to be published. Your suggestion would require preemptively knowing which release is bound for production (e.g., includes `-release`) versus having the ability to "promote" an existing tag after some more manual testing or stakeholder approval, for example. I'm going to leave this question unanswered because ideally I'd like to trigger the build when creating a release as described above. Hopefully there's another way. – ilyakam May 28 '21 at 22:47
  • Yeah, you are right. But, I think in case you couldn't find any other solution, you still can consider a specific release tag that is well tested and ready to be released. Then you can use this solution to trigger a pipeline and create a new `Release`. – Reza Ebrahimpour May 29 '21 at 05:08
  • If you didn't find any other solution or if my answer helped you, please accept or upvote the answer :) It will help a lot to me to increase the reputation. – Reza Ebrahimpour Jun 02 '21 at 08:26
  • 1
    Hi Reza, I upvoted your answer because I know you gave it your best shot and I sincerely appreciate the response. I'm going to leave it unanswered for now to signal to others that I'm still looking for the right feature on GitLab, if it exists. – ilyakam Jun 03 '21 at 22:09