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

一个人想着一个人 提交于 2020-04-29 14:51:54

问题


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.


回答1:


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




回答2:


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.




回答3:


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

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


来源:https://stackoverflow.com/questions/49514416/trigger-gitlab-ci-pipeline-only-when-there-is-a-new-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!