installing node on jenkins 2.0 using the pipeline plugin

牧云@^-^@ 提交于 2019-12-04 03:09:39

Either

node {
  withEnv(["PATH+NODE=${tool name: 'node-5.10.1', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'}/bin"]) {
    sh 'node -v'
  }
}

or

node {
  def nodeHome = tool name: 'node-5.10.1', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
  sh "${nodeHome}/bin/node -v"
}

should work. See JENKINS-28718 for further proposals.

By the way you can omit the type parameter and just use

tool 'node-5.10.1'

for brevity.

Andrey Prokopiev

For me work next code:

node(){
  def nodeHome = tool 'nodejs5'
  env.PATH="${env.PATH}:${nodeHome}/bin"
  ...
  sh 'npm install'
}

nodejs5 is the name of the tool specified in Jenkins configuration.

If anyone happens to deal with this issue on Jenkins running on Windows. Do the following:

def nodeHome = tool 'Node.js 6.9.5'
bat "\"${nodeHome}\"\\node.exe -v"
bat "\"${nodeHome}\"\\npm -v"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!