gitlab-cid示例1
default:
before_script:
- echo "start deploy"
- echo $CI_COMMIT_REF_NAME
# 阶段
stages:
- install
- buildDev
- buildTest
- buildProd
- deployDev
- deployTest
- deployProd
cache:
paths:
- node_modules/
# 安装依赖
install:
stage: install
# 此处的tags必须填入之前注册时自定的tag
tags:
- install
# 规定仅在dev、test、prod分支提交时才触发此阶段
only:
- dev
- test
- prod
# # 规定仅在package.json提交时才触发此阶段
# changes:
# - package.json
# 执行脚本
script:
- echo "start install"
- rm -rf ./node_modules
- npm install
# 打包dev分支
buildDev:
stage: buildDev
tags:
- buildDev
# 规定仅在dev分支提交时才触发此阶段
only:
- dev
script:
- echo "start dev build"
- rm -rf ./dist
- npm run build:dev
# 将此阶段产物传递至下一阶段
artifacts:
paths:
- dist/
# 打包test分支
buildTest:
stage: buildTest
tags:
- buildTest
# 规定仅在test分支提交时才触发此阶段
only:
- test
script:
- echo "start test build"
- rm -rf ./dist
- npm run build:test
# 将此阶段产物传递至下一阶段
artifacts:
paths:
- dist/
# 打包prod分支
buildProd:
stage: buildProd
tags:
- buildProd
# 规定仅在prod分支提交时才触发此阶段
only:
- prod
script:
- echo "start prod build"
- rm -rf ./dist
- npm run build:prod
# 将此阶段产物传递至下一阶段
artifacts:
paths:
- dist/
# 部署dev项目
deployDev:
stage: deployDev
tags:
- deployDev
only:
# 规定仅在dev分支提交时才触发此阶段
- dev
script:
- echo "start deploy Dev"
# 删除远端服务器的dist目录下的所有文件
- rsync -avz --delete --exclude ".git/" ./ rsync://192.168.56.106:873/html/
- echo "deploy Dev successfully"
# 部署test项目
deployTest:
stage: deployTest
tags:
- deployTest
only:
# 规定仅在test分支提交时才触发此阶段
- test
script:
- echo "start deploy Test"
# 删除远端服务器的dist目录下的所有文件
- rsync -avz --delete --exclude ".git/" ./ rsync://192.168.56.106:873/html/
- echo "deploy Test successfully"
# 部署prod项目
deployProd:
stage: deployProd
tags:
- deployProd
only:
# 规定仅在prod分支提交时才触发此阶段
- prod
script:
- echo "start deploy Prod"
- pwd
# 删除远端服务器的dist目录下的所有文件
- rsync -avz --delete --exclude ".git/" ./ rsync://192.168.56.106:873/html/
- echo "deploy Prod successfully"
本文来自博客园,作者:河北大学-徐小波,转载请注明原文链接:https://www.cnblogs.com/xuxiaobo/p/18606779