简体   繁体   中英

Is there any way to change branch name automatically inside the .gitlab-ci.yml file?

I am trying to build up my .gitlab-ci.yml file in order to accomplish proper pipeline run for my feature branches .

As my feature branches are going to be cloned from development, it will get specific .gitlab-ci.yml which I gave an example below:

# TCR Compiling Job    
TCR:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "master"'
      when: on_success
      changes:
        - tcr/**/*
    - if: '$CI_PIPELINE_SOURCE == "web" && $CI_COMMIT_BRANCH == "development"'
      when: manual
      changes:
        - tcr/**/*     
  
  script:
      - latexmk doc-operation-handbook-tcr.tex
  
  artifacts:
    name: "$CI_JOB_STAGE-$CI_COMMIT_REF_NAME"
    paths:
      - doc-operation-handbook.pdf
    when: on_success
    expire_in: 30 min

Inside the above example it can be seen there I have two different rules; one for master and one for development . But whenever a feature branch created, it is going to try to run this pipeline which there is no defined rules for that feature branch..

Is there any way to define that automatically whenever a feature branch is created? Like using $CI_COMMIT_BRANCH == "feature_branch" something like that.

Note: My feature branches are going to be deleted after a merge request done correctly.

You can use regex in your rules definition. For example:

rules:
# only for a ref that starts with "feature_branch_"
  - if: '$CI_COMMIT_REF_NAME == /^feature_branch_[a-Z0-9\-\_].*$/'
    when: always
# only for a tag ref that matches vX.Y.Z such as v1.5.2
  - if: '$CI_COMMIT_REF_NAME == /^v\d\.\d\.\d$/'
    when: manual

See the rules:if docs for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM