简体   繁体   English

基于gitlab CI中的git标签的条件自动部署

[英]Conditional auto-deploy based on git tag in gitlab CI

I'm setting up a deployment process for my website with gitlab CI. 我正在使用gitlab CI为我的网站设置部署过程。 I have a production website and a sub-domain with a staging deployment. 我有一个production网站和一个带有staging部署的子域。

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 . 我有一个文件.yaml配置如下:如果我推动master,我有一个production部署(有一个手动选项),如果我推动我的分支版本,我有一个自动部署在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 (eg feature ) on staging when specifying a tag (eg specifictag ) on a git push : 我们是几个工作的人,有时,我们希望能够在git push上指定标签(例如specifictag标签)时在staging上部署另一个分支(例如feature ):

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! 谢谢!

You can use regex, like 你可以使用正则表达式

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

And tag your commit, begin with "staging-". 并标记您的提交,以“staging-”开头。 When you push, the job should run. 当你推动时,工作应该运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM