前提:根據(jù)同事已經(jīng)配置好的 .gitlab-ci.yml
文件至朗,查看其參數(shù)的意義以及如何讓一個新的項目能自動構建。
stages:
- build
- deploy
variables:
GIT_CLEAN_FLAGS: -ffdx -e node_modules/
build:
stage: build
cache:
key: buildres
paths:
- dist
policy: push # 在作業(yè)完成時上傳緩存胸懈,但在作業(yè)開始時從不下載緩存
tags:
- ams_ci
only:
- master
script:
- npm install
- npm run build
deploy:
stage: deploy
cache:
key: buildres
paths:
- dist
policy: pull # 僅在作業(yè)開始時下載緩存,但在作業(yè)完成時從不上傳更改
tags:
- ams_ci
only:
- master
script:
- sshpass -p $password scp -r ./dist/* rss@119.23.**.**:/home/rss/www_ams # 將dist目錄里的文件推到服務器119.23.**.**:/home/rss/www_ams 目錄下,其中 password 在gitlab上配置细溅,如圖:
image.png
文檔地址:https://docs.gitlab.cn/jh/ci/侥涵,參數(shù)都能看到沼撕,需要注意GIT_CLEAN_FLAGS:
著重注意下 tags,需要注冊runner
windows安裝:https://docs.gitlab.cn/runner/install/windows.html
實際操作如圖:
注冊runner:https://docs.gitlab.cn/runner/register/
實際操作如圖:
成功后芜飘,在gitlab上可以看到:
測試:(本人注釋了deploy务豺,測試build階段,并將master分支改為aaa分支)
第一次報錯嗦明,如圖:
原因:
按照要求修改后笼沥,最后成功: