前提:根據(jù)同事已經(jīng)配置好的 .gitlab-ci.yml 文件,查看其參數(shù)的意義以及如何讓一個(gè)新的項(xiàng)目能自動(dòng)構(gòu)建。
stages:
- build
- deploy
variables:
GIT_CLEAN_FLAGS: -ffdx -e node_modules/
build:
stage: build
cache:
key: buildres
paths:
- dist
policy: push # 在作業(yè)完成時(shí)上傳緩存,但在作業(yè)開(kāi)始時(shí)從不下載緩存
tags:
- ams_ci
only:
- master
script:
- npm install
- npm run build
deploy:
stage: deploy
cache:
key: buildres
paths:
- dist
policy: pull # 僅在作業(yè)開(kāi)始時(shí)下載緩存,但在作業(yè)完成時(shí)從不上傳更改
tags:
- ams_ci
only:
- master
script:
- sshpass -p $password scp -r ./dist/* rss@119.23.**.**:/home/rss/www_ams # 將dist目錄里的文件推到服務(wù)器119.23.**.**:/home/rss/www_ams 目錄下,其中 password 在gitlab上配置,如圖:

image.png
文檔地址:https://docs.gitlab.cn/jh/ci/,參數(shù)都能看到,需要注意GIT_CLEAN_FLAGS:

著重注意下 tags,需要注冊(cè)runner
windows安裝:https://docs.gitlab.cn/runner/install/windows.html

實(shí)際操作如圖:

注冊(cè)runner:https://docs.gitlab.cn/runner/register/

實(shí)際操作如圖:

成功后,在gitlab上可以看到:

測(cè)試:(本人注釋了deploy,測(cè)試build階段,并將master分支改為aaa分支)
第一次報(bào)錯(cuò),如圖:

原因:

按照要求修改后,最后成功:
