簡介 GitLab CI/CD
什麼是 GitLab CI/CD?
GitLab CI/CD 的核心概念
GitLab CI/CD 範例
# .gitlab-ci.yml
# 定義 Pipeline 中的階段
stages:
- build
- test
- deploy
# 定義各階段中的 job
# 在每個 job 中,我們可以定義 script 欄位來指定要執行的指令
# 我們也可以使用不同的 image 來執行不同的操作
jobs:
# 編譯程式碼
build:
stage: build
script:
- npm install
- npm run build
artifacts:
paths:
- build/
# 執行測試
test:
stage: test
script:
- npm test
# 部署到生產環境
deploy:
stage: deploy
script:
- docker build -t myapp .
- docker tag myapp registry.example.com/myapp
- docker push registry.example.com/myapp
only:
- master # 只有在 master 分支上提交時才執行部署操作Last updated