使用管道插件在jenkins 2.0上安装节点 [英] installing node on jenkins 2.0 using the pipeline plugin
问题描述
我正在运行以下docker image jenkinsci/jenkins:2.0-rc-1
来试用jenkins 2.0和管道"视图.
I am running the following docker image jenkinsci/jenkins:2.0-rc-1
to try out jenkins 2.0, and the "pipeline" view.
我似乎无法安装节点.这是我的管道脚本:
I can't seem to install node. Here's my pipeline script:
node {
//tool([name: 'node-5.10.1', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'])
sh 'echo $(whoami)'
sh 'node -v'
}
运行时的响应是:
[ci] Running shell script
+ whoami
+ echo jenkins
jenkins
[Pipeline] sh
[ci] Running shell script
+ node -v
/../durable-3b0b1b07/script.sh: 2: /../durable-3b0b1b07/script.sh: node: not found
这是我尝试过的:
-
jenkins NodeJS工具(与自由式作业一起使用时可以正常工作)
the jenkins NodeJS tool (which works correctly when used with a freestyle job)
登录docker容器并手动为同一用户安装节点:
logging into the docker container and installing node manually, for the same user:
更新:
基于下面的Jesse Glick的答案,我将结果添加到了脚本PATH
:
Building on Jesse Glick's answer below, i added the result to my scripts PATH
:
node {
def nodeHome = tool name: 'node-5.10.1', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
env.PATH = "${nodeHome}/bin:${env.PATH}"
sh 'npm install'
}
推荐答案
都可以
node {
withEnv(["PATH+NODE=${tool name: 'node-5.10.1', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'}/bin"]) {
sh 'node -v'
}
}
或
node {
def nodeHome = tool name: 'node-5.10.1', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
sh "${nodeHome}/bin/node -v"
}
应该工作.有关更多建议,请参见 JENKINS-28718 .
should work. See JENKINS-28718 for further proposals.
通过这种方式,您可以省略type
参数,而只需使用
By the way you can omit the type
parameter and just use
tool 'node-5.10.1'
为简洁起见.
这篇关于使用管道插件在jenkins 2.0上安装节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!