gitlab ci/cd 多项目流水线制品合并方案

举报
拿我格子衫来 发表于 2022/03/17 22:48:05 2022/03/17
【摘要】 首先需要在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


  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43

子项目流水线

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


  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

在这里插入图片描述

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


  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53

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

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。