Gitlab Ci在第二份工作之后执行一份工作

时间:2020-03-20 10:21:00

标签: continuous-integration gitlab gitlab-ci

我有2个生产服务器,并且有2个手动作业,现在我想运行第一个作业之后的第二个作业。 我尝试使用键:之后,需要,但不起作用

请告诉我PROD_1作业完成后如何运行PROD_2作业,并且在第二项作业中不要使用when: manual

Deploy_Build_STAGE:
  variables:
    DEPLOY_DIR: "/var/www/my_stage_app"
  environment:
    name: STAGE
    url: https://stage.example.com/
  stage: Deploy
  tags:
    - stage
  only:
    - stage
  script:
    - preparing
    - cd drupal/
    - composer install -n --prefer-dist --ignore-platform-reqs --no-dev
    - yarn install
    - yarn build --no-progress
    - copy_files -s "./" -d "$DEPLOY_DIR/public_html/"
    - generate_drush_config
    - cd $DEPLOY_DIR/public_html/web/
    - drush cr
    - drush updb -y
    - drush cim -y
    - drush updb -y
    - drush cr
    - sudo systemctl restart nginx php7.1-fpm varnish


Deploy_Build_PROD_1:
  variables:
    DEPLOY_DIR: "/var/www/my_app/"
  environment:
    name: PROD_1
    url: https://example.com/
  stage: Deploy
  when: manual
#  allow_failure: false
  tags:
    - app1
  only:
    - new_prod
  script:
    - sudo systemctl stop nginx
    - preparing
    - cd drupal/
    - composer install -n --prefer-dist --ignore-platform-reqs --no-dev
    - yarn install
    - yarn build --no-progress
    - copy_files -s "./" -d "$DEPLOY_DIR/public_html/"
    - generate_drush_config
    - cd $DEPLOY_DIR/public_html/web/
    - test -d sites/default/files/ || mkdir sites/default/files/
    - drush cr
    - drush updb -y
    - drush cim -y
    - drush updb -y
    - drush cr
    - sudo systemctl restart nginx php7.1-fpm varnish




Deploy_Build_PROD_2:
  variables:
    DEPLOY_DIR: "/var/www/my_app/"
  environment:
    name: PROD_2
    url: https://example.com/
  stage: Deploy
  when: manual
  tags:
    - app2
  only:
    - new_prod
  script:
#    - sudo systemctl stop nginx
    - preparing
    - cd drupal/
    - composer install -n --prefer-dist --ignore-platform-reqs --no-dev
    - yarn install
    - yarn build --no-progress
    - copy_files -s "./" -d "$DEPLOY_DIR/public_html/"
    - generate_drush_config
    - cd $DEPLOY_DIR/public_html/web/
    - test -d sites/default/files/ || mkdir sites/default/files/
    - sudo systemctl restart nginx php7.1-fpm varnish

1 个答案:

答案 0 :(得分:0)

要保留已执行作业的顺序,请在您的Yaml中定义stages,然后按相同顺序执行作业。

stages:
  - first_stage
  - second_stage

job_1:
  stage: first_stage
...

job_2:
  stage: second_stage
...

或者您可以使用按顺序执行的默认阶段:

stages:
  - build
  - test
  - deploy