gitlab ci/cd 多项目流水线制品合并方案
【摘要】
首先需要在linux上安装 gitlab-runner 然后注册一个shell作为执行器的runner 该runner将应用于需要构建的项目
主流水线
stages:
- ready
- bu...
首先需要在linux上安装 gitlab-runner
然后注册一个shell作为执行器的runner
该runner将应用于需要构建的项目
主流水线
stages:
- ready
- build
- create
default:
tags:
- shell
ready_job:
stage: ready
script:
- echo '基座准备工作'
only:
- master
build_self_job:
stage: build
script:
- echo '开始构建多个应用,生成制品'
- ls -l
- cp -rf public/. /home/gitlab-runner/cicd-group/base
- cd /home/gitlab-runner/cicd-group/base
- ls -l
artifacts:
paths:
- public
only:
- master
build_other_job:
stage: build
trigger:
project: c860/sub-app
branch: master
strategy: depend
creat_app:
stage: create
script:
- cd /home/gitlab-runner/cicd-group/sub-app
- ls -l
子项目流水线
default:
tags:
- shell
build_job:
stage: deploy
script:
- echo '开始构建子应用'
- ls -l
- cp -rf public/. /home/gitlab-runner/cicd-group/sub-app
- cd /home/gitlab-runner/cicd-group/sub-app
- ls -l
artifacts:
paths:
- public
only:
- master
strategy: depend
该配置是关键,没有该配置只会创建子流水线,并不会等子流水线完成后,再执行主流水线后续作业。
有关多项目流水线的资料 以及 trigger
关键词的资料
https://docs.gitlab.com/ee/ci/pipelines/multi_project_pipelines.html
https://docs.gitlab.com/ee/ci/yaml/index.html#trigger
升级版本
stages:
- ready
- build
- create
.release_config:
tags:
- shell
only:
- tags
- master
cache:
key: $CI_PROJECT_NAME
paths:
- node_modules
ready_job:
extends: .release_config
stage: ready
script:
# 清空用于存放制品的目录
- rm -rf /home/gitlab-runner/cicd-group
- mkdir -p /home/gitlab-runner/cicd-group
build_self_job:
extends: .release_config
stage: build
script:
- cp -rf public/* /home/gitlab-runner/cicd-group
build_other_job:
stage: build
variables:
UPSTREAM_BUILD_TAG: $CI_COMMIT_TAG
trigger:
project: c860/sub-app
branch: $CI_COMMIT_TAG
strategy: depend
creat_app:
extends: .release_config
stage: create
script:
- cp -rf Dockerfile nginx-config.conf /home/gitlab-runner/cicd-group
- cd /home/gitlab-runner/cicd-group
- docker build -t 0901:$CI_COMMIT_TAG .
# - docker login -u $HARBOR_USERNAME -p $HARBOR_PWD $HARBOR_URL
# - docker push $APP_IMAGE_PRO_NAME # 推送镜像
# - docker rmi $APP_IMAGE_PRO_NAME # 删除本地镜像
# artifacts:
# paths:
# - cicd-group
https://docs.gitlab.com/ee/ci/yaml/#linking-pipelines-with-triggerstrategy
By default, the trigger job completes with the success status as soon as the downstream pipeline is created.
To force the trigger job to wait for the downstream (multi-project or child) pipeline to complete, use strategy: depend. This setting makes the trigger job wait with a “running” status until the triggered pipeline completes. At that point, the trigger job completes and displays the same status as the downstream job.
This setting can help keep your pipeline execution linear. In the following example, jobs from subsequent stages wait for the triggered pipeline to successfully complete before starting, which reduces parallelization
文章来源: fizzz.blog.csdn.net,作者:拿我格子衫来,版权归原作者所有,如需转载,请联系作者。
原文链接:fizzz.blog.csdn.net/article/details/119997277
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
作者其他文章
评论(0)