编写gitlab-runner .gitlab-ci.yml

Example

cache:

paths:

- node_modules # 缓存 node_modules

stages:

- install

- build

- deploy

install:

stage: install

only:

- master # 只对 master 的改动做处理

script:

- echo '安装依赖阶段'

# - yarn config set registry https://registry.npm.taobao.org

# - yarn config set sass-binary-site https://npm.taobao.org/mirrors/node-sass

- yarn

tags:

- test # 安装 gitlab-runner 时加的 tag

build:

stage: build

script:

- echo '构建阶段'

- yarn build

artifacts:

paths:

- dist

tags:

- test

deploy:

stage: deploy

script:

- echo '替换文件阶段'

- cd dist

- pwd

- whoami

- ssh root@xxx.xxx.xx.xxx

# 列出所有文件

- ssh root@xxx.xxx.xx.xxx "ls -a"

# 删项目文件夹下所有内容

- ssh root@xxx.xxx.xx.xxx "rm -rf ./home/myapp/test/*"

# 使用 scp 命令远程拷贝文件

- scp -r -P 22 ./* root@132.232.88.202:/home/myapp/test

tags:

- test

链接:https://juejin.im/post/5d712fcf6fb9a06b2766edd9