How to start gitlab-ci.yml only on the marked branch?

How to complete the .gitlab-ci.yml task only on the marked branch of the wizard?

job:
  script:
  - echo "Do something"
  only:
  - master
  - tags

The above code will work if any condition exists: main branch or tagged commit.

My goal is to launch this launch for production deployment, but this will require that it be on the branch of the wizard and be tagged (with version). Otherwise, I will have another job that will move forward if the tag is missing.

+19
source share
4 answers

This behavior is not yet supported by gitlab-ci, although there is an open problem to add it.

,

only:
  - master
only:
  - tags

( , ).

+3

, ,

only:
 - tags  # please mention the 's' compared to Sergio Tomasello solution
except:
 - branches

11.4.3

+1

12.

:

@jlenny {-Update.gitlab-ci.yml conditions-} MVC · 2

@jlenny 12.0 · 2

( )

, except , , only , , :

  only:
    - tags
  except:
    - branches

11.3.4

0

, , ( Product Vision 2019 , , ).

:

job_for_master_no_tags:
  stage: deploy
  script:
  - echo "Release to Staging"
  only:
  - master

job_for_master_tags_only:
  stage: deploy
  script:
  - echo "Release to Production"
  only:
  - tags
  except:
  - /^(?!master).+@/    # Ruby RegEx for anything not starting with 'master'
0

Source: https://habr.com/ru/post/1015742/


All Articles