Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger a GitLab pipeline for a tagged commit on branch master?

I want to trigger pipelines once I push tagged commits to the branch master. Although, I'm not sure if it works, since I have had no success so far.

.gitlab-ci.yml:

variables:
  JEKYLL_ENV: production
  LC_ALL: C.UTF-8

stages:
  - publish
  - release
  # - deploy

pages:
  stage: publish
  image: ruby
  rules:
    - if: $CI_COMMIT_BRANCH == "master" && $CI_COMMIT_TAG != ""
      when: always
  before_script:
    - gem install bundler
    - bundle install
  script:
    - bundle exec jekyll build -d public
  artifacts:
    paths:
    - public

release:
  stage: release
  image: registry.gitlab.com/gitlab-org/release-cli:latest
  rules:
    - if: $CI_COMMIT_BRANCH == "master" && $CI_COMMIT_TAG != ""
      when: always
  script:
    - echo 'running release job'
  release:
    name: 'Release $CI_COMMIT_TAG'
    description: 'Created using gitlab-ci.yml. $EXTRA_DESCRIPTION'
    tag_name: '$CI_COMMIT_TAG' 
    ref: '$CI_COMMIT_TAG'
  artifacts:
    paths:
    - public
    expire_in: 1 day

What I have tried:

`- if: '$CI_COMMIT_TAG && $CI_COMMIT_BRANCH == "master"'`

Although, this last rule doesn't trigger pipelines at all.

like image 869
jurordrained Avatar asked Oct 18 '25 02:10

jurordrained


1 Answers

Actual answer is in comments of accepted answer

This solution doesn't work since CI_COMMIT_BRANCH and CI_COMMIT_TAG have mutually exclusive availability in any given pipeline. If CI_COMMIT_TAG is present, that means it is a tag pipeline and CI_COMMIT_BRANCH is undefined. Conversely, if CI_COMMIT_BRANCH is present, CI_COMMIT_TAG must not be present. This is because, in terms of git semantic, tags do not belong to any branch, nor do they have any association with branches. Tags only point to a commit SHA which may be present in multiple branches or even no branches at all. – sytech

like image 175
Sameer Azeem Avatar answered Oct 20 '25 04:10

Sameer Azeem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!