iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 22
0
DevOps

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

GitLab CI:觸發流程實作

# Outline
一、論述
二、實作

# TL;DR

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

一、前言

本篇會將昨日的設計寫成 GitLab CI。

二、實作

stages:
  - commit
  - build
  - deploy

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

.dotnet-core:
  <<: *dotnet-core-runner
  before_script:
    - dotnet --version

.deploy:
  extends: .dotnet-core
  stage: deploy
  script:
    - Some Deploy Sripts
    - Force Push $TARGET Tag to Repository

test:
  extends: .dotnet-core
  stage: commit
  script:
    - dotnet test
  only:
    - branches

build:
  extends: .dotnet-core
  stage: build
  script:
    - Some Build Sripts
  only:
    - master@fntsr/dotnet-core-ci-cd

# 只要 `master` 有最新進度,就會自動 Deploy 的 Staging 環境。
deploy-staging:
  extends: .deploy
  only:
    - master@fntsr/dotnet-core-ci-cd
  variables:
    TARGET: staging

# Release 分支預期會以 `release/<major>.<minor>` 為名,像是 `release/1.12`。
# 只要 Release 分支有新進度,包括建立一個新的 Release 分支,就會將該進度自動部署到 UAT 環境。
deploy-uat:
  extends: .deploy
  only:
    - \^release/\d+\.\d+$\@fntsr/dotnet-core-ci-cd
  except:
    - tags
  variables:
    TARGET: uat

# 若想要部署到 Production 環境,就是在 Release 分支上進行 Tag,並且以 `v<major>.<minor>.<patch>` 格式為名
# 只要該 Commit 有標記該格式的 Tag,就可以透過 GitLab CI 手動部署到 Production 環境。
deploy-production:
  extends: .deploy
  only:
    - \^v\.\d+\.\d+.\d+$\@fntsr/dotnet-core-ci-cd
  except:
    - branches
  when: manual
  variables:
    TARGET: production

上一篇
GitLab CI:觸發流程設計
下一篇
Virtualize:Dockerize .NET Core Application
系列文
.NET Core 專案持續整合與部署31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言