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.
Actual answer is in comments of accepted answer
This solution doesn't work since
CI_COMMIT_BRANCHandCI_COMMIT_TAGhave mutually exclusive availability in any given pipeline. IfCI_COMMIT_TAGis present, that means it is a tag pipeline andCI_COMMIT_BRANCHis undefined. Conversely, ifCI_COMMIT_BRANCHis present,CI_COMMIT_TAGmust 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With