Gitlab中Vue的CI配置

关键点

  • cache: 指的是缓存, 常用于依赖安装中, 如几个jobs都需要安装相同的依赖, 可以使用依赖, 此时可以加快依赖的安装进度
  • artifacts: 将某个工件上传到GitLab提供下载或后续操作使用, 由于每个job启动时, 都会自动删除.gitignore中指定的文件, 因此对于依赖安装目录, 即可以使用cache, 也可以使用artifacts

具体配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
stages:
- install
- build
- deploy_production

variables:
SCRIPTS_STORAGE: /home/gitlab-runner/runner-scripts
DEPLOY_TO: /data/www/oms/client/dist/ # 要部署的目标服务器项目路径

cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- node_modules/

install:
stage: install
script: npm install
only:
- master

build:
stage: build
script:
- npm run build
only:
- master
artifacts:
paths:
- dist

deploy_production:
stage: deploy_production
script: rsync -avzP dist/ $DEPLOY_TO
only:
- master