NPM无法在Jenkins管道项目

时间:2016-07-21 10:00:47

标签: angularjs node.js jenkins npm angular-cli

我正在尝试使用Jenkins文件在Jenkins上构建一个angular2项目。该项目使用angular-cli生成。我无法通过脚本运行本地安装的模块。在我的情况下,在运行typings时调用安装后脚本typings install时,无法找到npm install

当我在本地构建项目时,在Windows上,一切正常。但是在Linux上的Jenkins中运行命令我得到了如上所述的问题。

我现在通过将./node_modules/.bin添加到Jenkins文件中的PATH来解决它,但我希望在使用npm时,本地安装的模块会自动添加到路径中: https://docs.npmjs.com/files/folders#executables

(我知道我应该使用npm bin的结果,而不是使用./node_modules/.bin

我的问题是:我没有正确理解文档吗?我真的需要手动将本地bin目录添加到PATH吗?我如何修复我的设置,所以我不需要这样做(不使用全局安装的包)?或者将npm bin添加到PATH的最佳方法是什么?

的package.json:

{
  "name": "hello",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "postinstall": "typings install",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test --watch=false",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "2.0.0-rc.4",
    "@angular/compiler": "2.0.0-rc.4",
    "@angular/core": "2.0.0-rc.4",
    "@angular/forms": "0.2.0",
    "@angular/http": "2.0.0-rc.4",
    "@angular/platform-browser": "2.0.0-rc.4",
    "@angular/platform-browser-dynamic": "2.0.0-rc.4",
    "@angular/router": "3.0.0-beta.2",
    "es6-shim": "0.35.1",
    "reflect-metadata": "0.1.3",
    "rxjs": "5.0.0-beta.6",
    "systemjs": "0.19.26",
    "zone.js": "0.6.12"
  },
  "devDependencies": {
    "angular-cli": "1.0.0-beta.10",
    "codelyzer": "0.0.20",
    "ember-cli-inject-live-reload": "1.4.0",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "0.13.22",
    "karma-chrome-launcher": "0.2.3",
    "karma-jasmine": "0.3.8",
    "karma-junit-reporter": "1.1.0",
    "protractor": "3.3.0",
    "ts-node": "0.5.5",
    "tslint": "3.11.0",
    "typescript": "1.8.10",
    "typings": "1.3.1"
  }
}

Jenkinsfile(摘录):

node {

  withNodeEnv {
      sh "npm install"
      sh "ng test"
  }

}

void withNodeEnv(Closure body) {
    String nodeTool = tool name: 'node4LTS', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'

    // Create environment with NodeJS added to the PATH.
    List nodeEnv = ["PATH+NODE=${nodeTool}/bin", "PATH+NODE_MODULES=./node_modules/.bin"]

    // Invoke the body closure within in the environment with NodeJS added.
    withEnv(nodeEnv) {
        body.call()
    }
}

我正在使用:

  • Jenkins:2.10(带NodeJS插件v0.2.1)
  • node:4.4.7(没有全局安装的软件包)
  • 角-CLI:1.0.0-beta.10

0 个答案:

没有答案