Can I configure for GitLab-CI to only run a particular job with a branch name pattern?

3

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

Briefly on GitFlow, it has nomenclature for branhces, one house has a goal:

  • master is the branch with the production code, so relatively stable code
  • develop is the branch with the 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

    ex: rc-1.2 is the launch candidate for the 1.2

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

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

build:
  stage: build
  script:
    - mvn compile

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

I'd like to add a job to run only on branches that follow the pattern rc-* . I did not find anything in the documentation regarding pattern name for jobs:only , but this is used in several corners in the GitLab web.

So, I ask:

  • Can I configure for GitLab-CI to only execute certain job for branches that satisfy the pattern rc-* ? If so, how do I do this?
asked by anonymous 26.02.2018 / 17:15

1 answer

0

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 branch verbatim. In the question, job:deploy-libs will be executed when called in the branch master or develop .

To use regular exepressions, put the expression / between slashes / . Then, as it is desired to add the rc-* pattern, in regex the equivalent would be (already putting the required bars) /^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-.*$/
    
11.06.2018 / 22:58