Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitLab only builds for specific tag names

Tags:

gitlab-ci

Is there a way to instruct the pipeline to only do a step for certain tags that matches a regular expression?

I would like it to do a deploy when I push a tag on the format 1.2.3 (for example). Is there a way to do this?

like image 615
Magnus Lundberg Avatar asked Jun 29 '17 20:06

Magnus Lundberg


People also ask

How do I assign tags to a GitLab Runner?

If you do not enable that option, this Runner will be configured as “Shared Runner,” so Gitlab will share the Runner for any project that doesn’t specify a Tag. To assign Tags to the Gitlab Runner, you need to navigate to the Administration area, and select your Runner and then, edit the configuration, like the screenshot above:

What are the different types of tags in Git?

Git supports two types of tags: Annotated tags: An unchangeable part of Git history. Lightweight (soft) tags: Tags that can be set and removed as needed. Many projects combine an annotated release tag with a stable branch. Consider setting deployment or release tags automatically.

What is the difference between tags and commits in GitLab-CI?

Just a side note: tags, branches and commits (or ref's) are all treated the same in GIT (and consequently GitLab-CI) in that regard. When you tag a commit ref you are not tagging on a particular branch, you are simply tagging a commit ref which can live on multiple branches simultaneously.

What is an annotated tag in Git?

Annotated tags: An unchangeable part of Git history. Lightweight (soft) tags: Tags that can be set and removed as needed. Many projects combine an annotated release tag with a stable branch. Consider setting deployment or release tags automatically. Create a lightweight tag. Create an annotated tag. Push the tags to the remote repository.


3 Answers

This should only be run for refs that are not branches named matching the given regex.

   job:
      only:
        - /^(\d+\.)?(\d+\.)?(\*|\d+)$/
      except:
        - branches
like image 113
Jonas Geiregat Avatar answered Oct 20 '22 14:10

Jonas Geiregat


Yes, you can do this with the only option:

job:
  # Use regexp
  only:
    - /^issue-.*$/


job:
  # Use special keywords
  only:
    - tags
    - triggers
    - schedules

See only/except (basic).

like image 21
Rufinus Avatar answered Oct 20 '22 14:10

Rufinus


You can also make use of rules:

job:
  script: echo "Hello, World!"
  rules:
    - if: '$CI_COMMIT_TAG =~ /^\d+\.\d+\.\d+$/'
like image 13
ricekot Avatar answered Oct 20 '22 14:10

ricekot