Hendouz
Hendouz

Reputation: 531

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.

Upvotes: 23

Views: 38781

Answers (4)

kadee
kadee

Reputation: 8854

The only keyword has been deprecated by GitLab (as mentioned by @frouo). It is recommended to use rules instead.

Example:

rules:
  - if: $CI_COMMIT_TAG

Upvotes: 0

Larry Cai
Larry Cai

Reputation: 59943

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

only:
  refs:
    - tags
  variables:
    - $CI_COMMIT_TAG =~ /^[Tt]icket-.*/

Upvotes: 10

Alex Montoya
Alex Montoya

Reputation: 5099

I recommend to use pattern in varibles-expression using commits

Example

build_api:
 stage: build
 script:
  - docker build --pull -t $CONTAINER_TEST_IMAGE .
  - docker push $CONTAINER_TEST_IMAGE
only:
  variables:
   - $CI_COMMIT_MESSAGE =~ /(\[pipeline\]|(merge))/     

Here i am saying that only execute that job when have [pipeline] or merge inside the commit. More info, here in gitlab

Upvotes: 5

Rekovni
Rekovni

Reputation: 7354

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.

Upvotes: 25

Related Questions