gitlab-ci window下構建Nodejs程式,會跳過npm install後面的其他指令碼
阿新 • • 發佈:2018-12-05
背景
最近在處理一個nodejs的構建程式,因為需要打包為win可執行程式,並且有現成的ci工具可以用,就找了一個window機子作為gitlab-runner註冊到gitlab伺服器上,本地利用node npm 安裝包,起服務測試都沒問題,但是在gitlab-ci伺服器上執行的時候,就出問題了。每次ci執行到一半,就結束了。附件還無法上傳,這是這次的問題
問題解決辦法
原始的CI配置檔案
image: 130.10.8.208:8889/node
variables:
CI_DEBUG_TRACE: "true"
stages:
- build
- buildexe
# 前端頁面打包
fed_build:
stage: build
script:
- mkdir build
- npm config set registry http://130.10.8.208/repository/bksx-npm
- npm config set sass-binary-site http://130.10.8.208/repository/node-sass
- npm config set phantomjs_cdnurl http://130.10.8.208/repository/phantomjs
- npm config list && npm install && npm run pro
- mkdir -p product/app
- mv build/* ./product/app
- cp server.config.js ./product/app
- cp soft/run.js ./product/app
- cp soft/package.json ./product/app
- cp soft/install/* ./product/install
- cd product/app
- npm install
only:
refs:
- dev
artifacts:
paths:
- product/
# 打包可執行.exe檔案
buildexe:
stage: buildexe
script:
- chcp 65001
- whoami
- copy server.config.js package
- cd package
- npm install
- npm run package
- cd zzzwwwzhzx
- npm install
- grunt
only:
refs:
- dev
tags:
- zyy
artifacts:
paths:
- package/zzzwwwzhzx/installer
後來在gitlab 官方網站發現類似的問題 ,如下所示,他們把shell=cmd這個預設值改為shell=powershell,這種方式,我們試了,並不是很好用,再找
後來發現另一個文章中的辦法, 文章中提到,在window下,預設是無法批量執行指令碼的。如果需要執行的話,需要在執行命令前加call 即可,修改後的內容地
image: 130.10.8.208:8889/node
variables:
CI_DEBUG_TRACE: "true"
stages:
- build
- buildexe
# 前端頁面打包
fed_build:
stage: build
script:
- mkdir build
- npm config set registry http://130.10.8.208/repository/bksx-npm
- npm config set sass-binary-site http://130.10.8.208/repository/node-sass
- npm config set phantomjs_cdnurl http://130.10.8.208/repository/phantomjs
- npm config list && npm install && npm run pro
- mkdir -p product/app
- mv build/* ./product/app
- cp server.config.js ./product/app
- cp soft/run.js ./product/app
- cp soft/package.json ./product/app
- cp soft/install/* ./product/install
- cd product/app
- npm install
only:
refs:
- dev
artifacts:
paths:
- product/
# 打包可執行.exe檔案
buildexe:
stage: buildexe
script:
- chcp 65001
- whoami
- copy server.config.js package
- cd package
- call npm install
- call npm run package
- cd bjswwwzhzx
- call npm install
- call grunt
only:
refs:
- dev
tags:
- zyy
artifacts:
paths:
- package/bjswwwzhzx/installer
問題解決