文章出處

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

當你提交之后,它可以自動執行,當前你也可以讓它只對某個分支執行!

感謝各位閱讀!


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()