Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional auto-deploy based on git tag in gitlab CI

I'm setting up a deployment process for my website with gitlab CI. I have a production website and a sub-domain with a staging deployment.

Let's say I have different branches among them : master and release. I have a file .yaml that is configured such that : if I push on master, I have a deployment on production (with a manual option) and if I push on my branch release, I have an automatic deployment on staging.

git push origin master 

deploys to production (with manual validation),

git push origin release 

deploys to staging. And any other branch that are pushed do not deploy.

We are several guys to work and, sometimes, we would like to be able to deploy another branch (e.g. feature) on staging when specifying a tag (e.g. specifictag) on a git push :

git tag specifictag    
git push origin feature --tags

This would be useful for me because sometimes some developers would like to test their codes before merging to release and we don't want to create a third environment. And of course we don't want to deploy every time we push on any branch.

stages:

  - staging

  - production

test-deployment:

  stage: staging

  script:

    - [...]

  only:

    - release

  tags:

    - extranetserver

prod-deployment:

  stage: production

  script:

    - [...]

  only:

    - master

  tags:

    - extranetserver

  when: manual

Has anyone an idea on how to use tag as a way to force a deployment when a specific tag is pushed ? Thanks!

like image 629
probaPerception Avatar asked Mar 31 '17 12:03

probaPerception


People also ask

What parameter determines where an app is deployed in GitLab?

NOTE: Note: The environment keyword defines where the app is deployed. The environment name and url is exposed in various places within GitLab. Each time a job that has an environment specified succeeds, a deployment is recorded, along with the Git SHA, and environment name.

What is Before_script in GitLab CI?

These are scripts that you choose to be run before the job is executed or after the job is executed. These can also be defined at the top level of the YAML file (where jobs are defined) and they'll apply to all jobs in the . gitlab-ci. yml file.

What is the use of tags in GitLab CI Yml?

gitlab-ci. yml , you can specify some jobs with the tag testing . If a runner with this tag associated is available, it will pickup the job. In Git, within your repository, tags are used to mark a specific commit.


1 Answers

You can use regex, like

test-deployment:
    only:
        - /^staging-/

And tag your commit, begin with "staging-". When you push, the job should run.

like image 156
jolooket Avatar answered Oct 21 '22 13:10

jolooket