文档
基本使用步骤
- 在gitlab的服务器里面安装runner
- 为目标工程注册runner
- 为项目添加CI配置文件.gitlab-ci.yml
基本配置
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 54 55 56 57 58 59 60 61 62 63 |
stages: - prepare - test - build - deploy variables: # 项目名称 PROJECT_NAME: 'xunyouplatform' # 编译后需要打包的文件列表 RELEASE_FILES: 'output\xxx.dll,output\xxx.pdb' EMAILSENT: 'dev.list@xunyou.com test.list@xunyou.com ops.list@xunyou.com' PROJECT_TITLE: '${PROJECT_NAME}.(${CI_COMMIT_REF_NAME})' GIT_STRATEGY: none test: stage: test script: # 单元测试命令 - 'cmd.exe /c "echo %cd%"' build: stage: build script: # 编译命令, 依赖项子模块 - 'git submodule update --init -- "3rd-party"' - 'git submodule update --init -- "build-tools"' - 'git submodule update --init -- "xunyoucommon"' - 'git submodule update --init -- "xunyoukernel"' - 'git submodule update --init -- "soui"' - 'soui\Build.bat' - 'devenv.com soui\soui.sln /build "Release"' - 'cd soui' - 'Rename-Item bin bin_dll' - 'cd ..' - 'msbuild.exe XYPlatform\XYPlatformNew.vcxproj /t:rebuild /p:Configuration=Release /p:Platform=x86' # 邮件备注消息, 可为空 - '$message = "无备注"' - 'ci.bat make "$env:CI_PROJECT_DIR" "$env:PROJECT_NAME" "$env:RELEASE_FILES" "$env:EMAILSENT" "$env:PROJECT_TITLE" $message' - 'dir "$env:CI_PROJECT_DIR\release\"' artifacts: name: ${PROJECT_TITLE} paths: - release/ before_script: - 'cmd.exe /c "echo %date% %time%"' prepare: stage: prepare when: manual allow_failure: false variables: GIT_STRATEGY: clone script: - 'echo ok' deploy: stage: deploy dependencies: - build script: - 'ci.bat deploy "$env:CI_PROJECT_DIR"' |
遇到的问题
手动触发job
1 2 3 4 5 6 7 |
build_job1: stage: build when: manual except: - web script: - 'aaaa' |
某状态多个任务
- stage同属build
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 |
Build_XYInteractive: stage: build when: manual variables: RELEASE_FILES: 'Release\XYInteractive.dll' before_script: - 'echo "--------------------Start Update submodule 3rd-party--------------------"' script: - 'echo "--------------------Start Compile XYInteractive--------------------"' artifacts: name: ${PROJECT_TITLE} paths: - release_bak/ Build_XYBase: stage: build when: manual variables: RELEASE_FILES: 'Release\XYBase.dll' before_script: - 'echo "--------------------Start Update submodule 3rd-party--------------------"' script: - 'echo "--------------------Start Compile XunYouKernel--------------------"' artifacts: name: ${PROJECT_TITLE} paths: - release_bak/ |
关联当前阶段和上个阶段的多个任务
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 |
stages: - prepare - test - build - deploy Build_All: stage: build when: manual Build_XYBase: stage: build when: manual Build_XYInteractive: stage: build when: manual deploy: stage: deploy when: manual dependencies: - Build_All - Build_XYBase - Build_XYInteractive script: - 'ci.bat deploy "$env:CI_PROJECT_DIR"' |
限制pipeline的并发
- 这个功能需要较新版本的CI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
stages: - test - deploy unit_test: resource_group: unit_test image: stage: test before_script: script: - pytest coverage: '/TOTAL.*\s+(\d+%)$/' deploy_qa: stage: deploy image: before_script: script: only: refs: - master |
resource_group: $CI_ENVIRONMENT_NAME
... 限制环境resource_group: $CI_JOB_NAME
... 限制job执行resource_group: $CI_COMMIT_REF_NAME:$CI_JOB_NAME
... 限制分支上的job执行resource_group: $CI_COMMIT_REF_NAME:$CI_ENVIRONMENT_NAME
... 限制相关分支的环境resource_group: $CI_PROJECT_NAME
... 限制了整个pipeline(放stages前)
控制代码的更新
- 下面这个阶段是最先执行的stage,里面设置了变量GIT_STRATEGY的值
- 如果全局也有设置这个变量,它的值会被这里更新
- 区别
- clone:每次运行pipeline会删掉代码,重新拉取
- fetch:不删代码了,但是会把上一次生成的二进制文件清理掉
- none:不删代码,也不删二进制,也不管代码的更新,需要我们添加更新代码的脚本
1 2 3 4 5 6 7 8 |
prepare: stage: prepare when: manual allow_failure: false variables: GIT_STRATEGY: fetch script: - 'echo ok' |
本文为原创文章,版权归Aet所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ 【AcWing 语法基础课 第四讲】02/23
- ♥ 结构型:委托模式07/28
- ♥ Visual Studio:管理工程文件10/14
- ♥ 【Javascript】try...catch,try…catch…finally,自定义Error,扩展Error04/13
- ♥ Nginx 变量一10/26
- ♥ 连接查询-子查询10/26
热评文章
- * 暂无