【问题标题】:Is there any way to make in Gitlab CI/CD a stage with two stages inside?有没有办法在 Gitlab CI/CD 中制作一个里面有两个阶段的阶段?
【发布时间】:2020-11-06 07:14:11
【问题描述】:

我有一个包含两个阶段的 .gitlab-ci.yml 文件,我希望将这些阶段放在一个称为发布的一般阶段内。换句话说,我希望在发行版中拥有第 1 阶段和第 2 阶段。我的 .gitlab-ci.yml 文件是这样的:

 image: google/cloud-sdk:slim

stages: 
  - deploy-website
  - deploy-cloud-function 
 
before_script:
  - gcloud auth activate-service-account --key-file $GOOGLE_SERVICE_ACCOUNT_FILE
  - gcloud config set project $GOOGLE_PROJECT_ID

deploy-website:
  stage: deploy-website
  script:
    - gsutil -m rm gs://ahinko.com/**
    - gsutil -m cp -R src/client-side/* gs://ahinko.com
  environment:
    name: production
    url: https://ahinko.com
  only: 
    - ci-test

deploy-cloud-function: 
  stage: deploy-cloud-function
  script:
    - gcloud functions deploy send_contact --entry-point=send_contact_form --ingress-settings=all --runtime=python37 --source=src/server-side/cf-send-email/ --trigger-http
  environment: 
    name: production
    url: https://ahinko.com
  only:
    - ci-test

【问题讨论】:

    标签: continuous-integration gitlab continuous-deployment gitlab-ci-runner continuous-delivery


    【解决方案1】:

    要实现你想要的,你只需要使用相同的舞台名称,比如

     image: google/cloud-sdk:slim
    
    stages: 
      - release
     
    before_script:
      - gcloud auth activate-service-account --key-file $GOOGLE_SERVICE_ACCOUNT_FILE
      - gcloud config set project $GOOGLE_PROJECT_ID
    
    deploy-website:
      stage: release
      script:
        - gsutil -m rm gs://ahinko.com/**
        - gsutil -m cp -R src/client-side/* gs://ahinko.com
      environment:
        name: production
        url: https://ahinko.com
      only: 
        - ci-test
    
    deploy-cloud-function: 
      stage: release
      script:
        - gcloud functions deploy send_contact --entry-point=send_contact_form --ingress-settings=all --runtime=python37 --source=src/server-side/cf-send-email/ --trigger-http
      environment: 
        name: production
        url: https://ahinko.com
      only:
        - ci-test
    
    

    但如果你这样做,你的工作将同时开始。 为避免这种行为,您需要将作业更改为手动启动

    when: manual
    

    【讨论】:

    • 太棒了!它解决了它!但是如果第一个作业成功并且在成功的一定时间之后有没有办法执行第二个作业?
    • 一切皆有可能,但您必须在作业中使用 shell 脚本。
    猜你喜欢
    • 2020-12-13
    • 2022-11-14
    • 2021-11-02
    • 2017-10-06
    • 1970-01-01
    • 2021-11-30
    • 2022-06-10
    • 1970-01-01
    • 2022-11-08
    相关资源
    最近更新 更多