continuous-integrationgitlabgitlab-ci

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.


Solution

  • 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