iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 16
0
DevOps

.NET Core 專案持續整合與部署系列 第 16

GitLab CI:Runner 以及初始設定檔案

  • 分享至 

  • xImage
  •  

在國慶連假前,此系列文每天的發文時都會以最簡陳述為主,以求在繁忙的日常中,至少能先維持挑戰鐵人賽的進度,並且逐漸拓展思路與系列構成。預期會在國慶聯假好好的去修文。

先在 macOS 上安裝 GitLab Runner 系統套件

$ brew install gitlab-runner
==> Downloading https://homebrew.bintray.com/bottles/gitlab-runner-12.3.0.mojave
==> Downloading from https://akamai.bintray.com/c7/c7d325e3468921ce8728ac3654856
######################################################################## 100.0%
==> Pouring gitlab-runner-12.3.0.mojave.bottle.tar.gz
==> Caveats
To have launchd start gitlab-runner now and restart at login:
  brew services start gitlab-runner
Or, if you don't want/need a background service you can just run:
  gitlab-runner start
==> Summary
?  /usr/local/Cellar/gitlab-runner/12.3.0: 8 files, 44.6MB

然後註冊 Runner

$ gitlab-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
https://gitlab.com/
Please enter the gitlab-ci token for this runner:
q5NZbwpFZyNvXXXXXXXX
Please enter the gitlab-ci description for this runner:
[ironman-macos]:
Please enter the gitlab-ci tags for this runner (comma separated):
ironman,docker
Registering runner... succeeded                     runner=q5NZbwpF
Please enter the executor: custom, docker, parallels, ssh, virtualbox, docker+machine, docker-ssh, shell, docker-ssh+machine, kubernetes:
docker
Please enter the default Docker image (e.g. ruby:2.6):
alpine:latest
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

然後在專案根目錄下建立 .gitlab-ci.yml 檔案,並輸入以下內容:

stages:
  - commit

.dotnet-core-runner: &dotnet-core-runner
  image: mcr.microsoft.com/dotnet/core/sdk:3.0
  tags:
    - docker

.dotnet-core: &dotnet-core
  <<: *dotnet-core-runner
  before_script:
    - dotnet --version
  only:
    - master
    - merge_requests

unit-test:
  <<: *dotnet-core
  stage: commit
  script:
    - dotnet test

這樣只要該專案的任何分支提 Merge Request 時,就會先透過 Docker 建立 .NET Core SDK 的容器,在裡面執行 dotnet test ,並將結果回傳給 GitLab CI,以確認是否通過。只有在結果是通過時,才有辦法合併。而當合併到 master 後,也會執行一次,確保合併後程式碼沒有出錯。


上一篇
Virtualize:透過 Docker 建置 .NET Core 專案
下一篇
導讀:持續整合、交付、部署、釋出
系列文
.NET Core 專案持續整合與部署31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言