使用管道插件在 jenkins 2.0 上安装节点 [英] installing node on jenkins 2.0 using the pipeline plugin
问题描述
我正在运行以下 docker 映像 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屋!