Can I set up Gitlab-CI to only run a particular job with a branch name Pattern?

Asked

Viewed 353 times

3

I’m using Gitlab for code evolution management. It’s all quiet about it. Usage merge-requests to review code changes. I also generally use the Gitflow, only using the name rc-* for launch branches (Gitflow provides release-*).

Briefly about Gitflow, it has nomenclature for branhces, house one has a goal:

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

    ex: rc-1.2 is the release candidate for the version 1.2

In Gitlab, I can set up a build using the Gitlab CI. This configuration is done in the file .gitlab-ci.yml. In this configuration file, I can determine Jobs which are executed conditionally (documentation).

For example, I might want Gitlab to only run job deploy-lib in the 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 one job to only run in branches that follow the Pattern rc-*. I found nothing in the documentation regarding Pattern name to the jobs:only, but this is used in various corners on the Gitlab web.

So I ask:

  • I can configure for Gitlab-CI to only run certain job for branches that Pattern rc-*? If yes, how do I do it?

1 answer

0


According to the documentation, yes, it is possible.

Read to detailed documentation

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

To use regular pressure, put the expression /between bars/. So how is it desired to add the pattern rc-*, 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-.*$/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.