Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger Gitlab-CI Pipeline only when there is a new tag

I have following gitlab-ci conf. file:

before_script:
  - echo %CI_BUILD_REF%
  - echo %CI_PROJECT_DIR%

stages:
  - createPBLs
  - build
  - package


create PBLs:
  stage: createPBLs
  script: 
    - xcopy /y /s "%CI_PROJECT_DIR%" "C:\Bauen\"
    - cd "C:\Bauen\"
    - ./run_orcascript.cmd


build:
  stage: build
  script:
  - cd "C:\Bauen\"
  - ./run_pbc.cmd
  except:
  - master

build_master:
  stage: build
  script:
  - cd "C:\Bauen\"
  - ./run_pbcm.cmd
  only:
  - master

package:
  stage: package
  script:
  - cd "C:\Bauen\"
  - ./cpfiles.cmd
  artifacts:
    expire_in: 1 week
    name: "%CI_COMMIT_REF_NAME%"
    paths:
      - GitLab-Build

How can I add the rule that the pipeline will ONLY trigger if a new tag has been added to a branch? The tag should start with "Ticket/ticket_"

Currently he is building for every push.

like image 278
Hendouz Avatar asked Mar 27 '18 13:03

Hendouz


People also ask

What triggers GitLab pipeline?

GitLab CI/CD Trigger is the most common and convenient technique for triggering CI/CD. GitLab CI/CD pipelines, by default, are executed automatically when new commits are pushed to a repository and do not require any intervention once created.

How do I trigger GitLab pipeline from another pipeline?

Go to Settings → CI/CD → Pipeline triggers → Add Trigger . It will create a trigger with a TOKEN string, which then can be copied into the curl command of gitlab-ci. yml of project A. Note: The triggers under only is necessary to define the rules.

How do you trigger a pipeline on a merge request?

Create a new merge request from a source branch with one or more commits. Push a new commit to the source branch for a merge request. Select Run pipeline from the Pipelines tab in a merge request.

How tags work in GitLab?

If a runner with this tag associated is available, it will pickup the job. In Git, within your repository, tags are used to mark a specific commit. It is often used to tag a version. The two concepts can be mixed up when you use tags (in Git) to start your pipeline in GitLab CI.


2 Answers

You need to use only syntax:

only:
  - tags

This would trigger for any Tag being pushed. If you want to be a bit more specific you can do:

only:
  - /Ticket\/ticket\_.*/

which would build for any push with the Ticket/ticket_ tag.

like image 96
Rekovni Avatar answered Sep 21 '22 14:09

Rekovni


below could be more readable, see only:varibles@gitlab-ci docs with refs:tags

  only:
    refs:
      - tags
    variables:
      - $CI_COMMIT_TAG =~ /^[Tt]icket-.*/
like image 31
Larry Cai Avatar answered Sep 25 '22 14:09

Larry Cai