在Gitlab-ci中使用NPM发布节点模块不起作用

时间:2017-11-03 16:53:41

标签: npm gitlab-ci-runner npm-publish

我正在使用gitlab-ci为我的CI / CD将NPM模块发布到注册表。以下是我的gitlab-ci.yml文件

image: docker:latest

variables:
  DOCKER_DRIVER: overlay2

services:
- docker:dind

cache:
  untracked: true
  key: "$CI_COMMIT_REF_NAME"
  paths:
    - node_modules/
stages:
    - setup

job-setup:
   stage: setup
   tags:
    - angular
   image: node:alpine
   except: 
    - tags
   script:
     - npm set registry https://registry.npmjs.org
     - npm i
     - cp .npmrc ~/.npmrc
     - npm publish --registry https://registry.npmjs.org

我在publish命令上收到以下警告消息。模块已发布但模块中的/ dist文件夹丢失。

npm WARN prepublish-on-install As of npm@5, `prepublish` scripts are deprecated.
npm WARN prepublish-on-install Use `prepare` for build steps and `prepublishOnly` for upload-only.
npm WARN prepublish-on-install See the deprecation note in `npm help scripts` for more information.
npm WARN lifecycle my_npm_module@1.1.1~prepublish: cannot run in wd %s %s (wd=%s) my_npm_module@1.1.1 npm run build /builds/code/my_npm_module
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

NPM在“工作目录”(wd)中运行存在问题,我不知道如何解决它。我在Centos上运行gitlab-ci。

1 个答案:

答案 0 :(得分:2)

npm拒绝从您的package.json运行构建脚本,因为它是作为root运行的。添加

echo "unsafe-perm = true" >> ~/.npmrc

在调用gitlab-ci.yml之前,先进入npm脚本。