How to run Gitlab CI only for specific branches and tags?

Instead of using only/except you can use rules which are more powerful.

Rules support regex pattern matching.

Your rule for excepting only specific kind of branches/tags like dev_1.0, dev_1.1, dev_1.2 should look like:

rules:
    - if: '$CI_COMMIT_BRANCH =~ /^dev_[0-9]+\.[0-9]+$/ || $CI_COMMIT_TAG =~ /^dev_[0-9]+\.[0-9]+$/'

Predefined environment variables like CI_COMMIT_BRANCH and CI_COMMIT_TAG are described here.


Sounds like a regular expression question. I just created a project on gitlab.com for the regular expression.

File: .gitlab-ci.yml

project_dev:
  # Irrelevant keys is skipped
  script:
    - echo "Hello World"
  only:
    - develop
    - release
    - master
    - /^dev_[0-9]+(?:.[0-9]+)+$/ # regular expression

I was pushed all of tags you mentioned to test this regular expression.

Tags

As you can see , It will match tags like dev_1.0, dev_1.1, but the job project_dev will not be triggered by tag dev1.2, You can check the result on pipeline pages

Pipelines