【发布时间】:2020-08-01 19:24:11
【问题描述】:
我想向 REST API 发送有关部署状态的报告。
它应该独立于部署作业(因为 $IMAGE2 依赖项),因为我想在其他项目中使用报告作业。
所以我在 Gitlab CI 中创建了两个工作,如下所示:
deploy:
stage: deploy
image: $IMAGE1
script:
- cd ${CI_PROJECT_DIR} && echo 'Failed' > deployment-status
# some codes to deploy and exit 1 if not successful
- cd ${CI_PROJECT_DIR} && echo 'Passed' > deployment-status #This line run only when deployment is successful
when: manual
artifacts:
when: always
paths:
- deployment-status
report-deployment:
stage: post-deploy
image: $IMAGE2
script:
- cd ${CI_PROJECT_DIR} && cat deployment-status
# some codes to report the status of deployment to an API
when: always
needs: ["deploy"]
在上述解决方案中,取决于部署,我将deployment-status 填充为Passed/Failed,并在下一个作业中使用deployment-status 工件文件来获取有关部署状态的信息并进行报告。
上面的解决方案有一些问题:
- 除非我触发手动作业,否则管道状态将为running。 (因为report-deployment 需要deploy 的工作)
- 如果我尝试触发 deploy 作业两次,则只有一份报告被发送到 API。
Image of problems
【问题讨论】:
-
嗨。为什么不把 API 调用放到
deploy阶段呢? -
我希望
report-deployment工作是一个单独的工作(类似模板),可以在其他项目中使用。并且合并 $IMAGE1 和 $IMAGE2 依赖项并不干净。
标签: continuous-integration gitlab gitlab-ci gitlab-ci-runner