GitlabCi deploy on multiple servers

喜夏-厌秋 提交于 2019-12-21 18:35:13

问题


I use Gitlab runner and works fine for a single server. The gitlab-ci.yml is simple:

stages:
  - test
  - deploy

test:
  stage: test
  image: php
  tags:
      - docker
  script:
      - echo "Run tests..."
deploy:
    stage: deploy
    tags:
      - shell
    script:
      - sh deploy.sh

As i said this is fine for a single server but to deploy same app on another server? I tried with same gitlab-runner config (same conf.toml) but then it was only updating one of them randomly.

Is there somehow gitlab Ci to be triggered by more than 1 runner and deploy all of them according gitlab-ci.yml?


回答1:


You can register several runners (e.g. tagged serverA and serverB) from different servers and have multiple deployment jobs, each of them performed by a different runner. This is because you can set more than one tag in a job and only a runner having all the tags will be used.

stages:
  - test
  - deploy

test:
  stage: test
  image: php
  tags:
      - docker
  script:
      - echo "Run tests..."

deployA:
    stage: deploy
    tags:
      - shell
      - serverA
    script:
      - sh deploy.sh

deployB:
    stage: deploy
    tags:
      - shell
      - serverB
    script:
      - sh deploy.sh

However, take into account a situation when one of the deployment jobs fails - this would end up in you having two different versions of the code on the servers. Depending on your situation this might or might not be a problem.




回答2:


Yes there is, just set up two jobs for the same stage:

stages:
  - deploy

deploy:one:
  stage: deploy
  script:
    - echo "Hello CI one"

deploy:two:
  stage: deploy
  script:
    - echo "Hello CI two"

If necessary you can use tags on your runners to choose which one to use.



来源:https://stackoverflow.com/questions/38553739/gitlabci-deploy-on-multiple-servers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!