Git~GitLab当它是一个CI工具时

CI我们都知道,它是持续集成的意思,主要可以自动处理包括编译,测试,发布等一系列的过程,而GitLab也同样包含了这些功能,我们可以通过pipeline很容易的实现一个软件从编译,测试,发布的自动化过程,下面我们来看一下!

首先你需要添加.gitlab-ci.yml这个文件,它就是我们的执行管道,它里若干个job组成,而每个job对应上图的一个阶段,它们是顺序执行的,当一个链条出现问题,它下面的job就不会被执行了。

我们可以在这个文件里定义自己项目的一些阶段,每个阶段依赖的image镜像都可以分别设置,非常灵活

stages:
- build
- cleanup_build
- test
- deploy
- cleanup

build_job:
  stage: build
  script:
  - make build

cleanup_build_job:
  stage: cleanup_build
  script:
  - cleanup build when failed
  when: on_failure

test_job:
  stage: test
  script:
  - make test

deploy_job:
  stage: deploy
  script:
  - make deploy
  when: manual

cleanup_job:
  stage: cleanup
  script:
  - cleanup after jobs
  when: always

如果你是一个dotnetcore的项目,你可以为它设置restore,build,test,publish等阶段

stages:
-restore
- build
- test
- deploy

restore_job:
  stage: restore
  script:
  - dotnet restore test.csproj

build_job:
  stage:build
  script:
  - dotnet build test.csproj

test_job:
  stage: test
  script:
  - dotnet test test.csproj

deploy_job:
  stage: deploy
  script:
  - make deploy
  when: manual

当你提交之后,它可以自动执行,当前你也可以让它只对某个分支执行!

感谢各位阅读!

原文地址:https://www.cnblogs.com/lori/p/7875821.html