3

我正在使用 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

我在发布命令上收到以下警告消息。模块已发布,但模块中的 /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。

4

1 回答 1

8

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

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

gitlab-ci.yml调用npm.

于 2018-10-20T22:41:25.613 回答