如何配置多个手动,并行作业?

时间:2017-05-22 21:05:06

标签: continuous-integration gitlab-ci

我有一个像这样的管道设置的应用程序:

图A

Figure A - 2 stage pipeline

使用这样的.gitlab-ci.yml文件

stages:
  - test
  - deploy

test:
  script:
    - bash run_tests.sh

deploy_staging:
  stage: deploy
  script:
    - rsync -rltvz --delete -e ssh --exclude=.git* public/ user@staging_node:/path/to/directory
  environment:
    name: staging
    url: https://staging.app.example.com
  only:
    - master

deploy_production:
  stage: deploy
  script:
    - rsync -rltvz --delete -e ssh --exclude=.git* public/ user@production_node1:/path/to/directory
    - rsync -rltvz --delete -e ssh --exclude=.git* public/ user@production_node2:/path/to/directory
  environment:
    name: production
    url: https://app.example.com
  when: manual
  only:
    - master

我有另外一个我想要部署的应用程序,但我想使用并行作业,如下所示:

图B

Figure B - 3 stage pipeline

在图A中,deploy_production是一个手动步骤(例如rsync到多个服务器节点的目录);在图B中,部署到deploy_node1deploy_node2只需一步(例如比rsync更多的时钟密集时间),通过Gitlab UI手动触发。

如何配置.gitlab-ci.yml并行运行部署作业,同时仍保持一键式手动部署?

更新(回应Jakub Kania的回答):

这是你的想法,Jakub?

尝试使用触发器,引导我走向.gitlab-ci.yml

stages:
  - test
  - stage
  - deploy

test:
  script:
    - bash run_tests.sh

staging:
  stage: stage
  script:
    - rsync -rltvz --delete -e ssh --exclude=.git* public/ user@staging_node:/path/to/directory
  environment:
    name: staging
    url: https://staging.app.example.com
  only:
    - master
  except:
    - triggers

deploy_trigger:
  stage: deploy
  script:
    - "curl -X POST -F token=TOKEN -F ref=master https://gitlab.example.com/api/v4/projects/1234/trigger/pipeline"
  environment:
    name: production
    url: https://app.example.com
  only:
    - master
  except:
    - triggers
  when: manual

deploy_node1:
  stage: deploy
  script:
    - rsync -rltvz --delete -e ssh --exclude=.git* public/ user@production_node1:/path/to/directory
  environment:
    name: production
    url: https://app.example.com
  only:
    - master
    - triggers

deploy_node2:
  stage: deploy
  script:
    - rsync -rltvz --delete -e ssh --exclude=.git* public/ user@production_node2:/path/to/directory
  environment:
    name: production
    url: https://app.example.com
  only:
    - master
    - triggers

1 个答案:

答案 0 :(得分:1)

使用trigger。设置部署任务以运行only触发器,并使手动操作成为将使用cURL调用触发器的操作。

相关问题