continuous-integration – Can I configure GitLab-CI to only run a certain job with a branch name pattern?

Question:

I'm using GitLab for code evolution management. All smooth about that. Use merge-requests to review code changes. I also generally use GitFlow , except using the name rc-* for release branches (GitFlow predicts release-* ).

Briefly about GitFlow, it has nomenclature for whites, each one has a goal:

  • master is the branch with production code, so relatively stable code
  • develop is the branch with development code, so relatively unstable code
  • rc-* is the branch with the release candidate , is derived from develop and (when mature enough) will be integrated into master

    eg rc-1.2 is the release candidate for version 1.2

In GitLab, I can configure a build using GitLab CI . This configuration is done in the .gitlab-ci.yml file. In this configuration file, I can determine jobs that run conditionally ( documentation ).

For example, I might want GitLab to only run the deploy-lib job on the master and develop branches:

build:
  stage: build
  script:
    - mvn compile

deploy-lib:
  stage: deploy
  script:
    - mvn deploy
  only:
    - master
    - develop

I would like to add a job to only run on branches that follow the rc-* pattern . I didn't find anything in the documentation regarding the pattern name for jobs:only , but this is used in many places in GitLab web.

So, I ask:

  • Can I configure GitLab-CI to only run a certain job for branches that satisfy the rc-* pattern ? If yes, how do I do this?

Answer:

According to the documentation, yes, it is possible.

Read the detailed documentation

In addition to keywords (such as branches and tags ), you can specify the name of the verbatim branch . In question, job:deploy-libs will run when called in the master or develop branch .

To use regular expressions, enclose the expression /in slashes/ . So, as you want to add the pattern rc-* , in regex the equivalent would be (already putting the required slashes) /^rc-.*$/

In this case, the .gitlab-ci.yml would look like this:

build:
  stage: build
  script:
    - mvn compile

deploy-lib:
  stage: deploy
  script:
    - mvn deploy
  only:
    - master
    - develop
    - /^rc-.*$/
Scroll to Top
AllEscort