参考Jenkins Starting with Pipeline doing a Node.js test,配置NodeJS开发环境
插件
首先下载NodeJS插件,进入Manage Jenkins -> Manage Plugins -> Available,搜索NodeJS插件并安装
配置
插件安装完成后,进入Manage Jenkins -> Global Tool Configuration,会出现NodeJS的配置选项
点击NodeJS Insllation,设置Name属性,选择要安装的NodeJS版本,以及待安装的全局软件,保存设置
Pipeline
新建Pipeline工程test,在配置时输入如下脚本
pipeline里引用tool
pipeline {
agent any
tools {nodejs “node”}
stages {
stage(‘Example’) {
steps {
sh ‘npm config ls’
sh ‘’’
node -v
npm -v
gulp -v
hexo -v
‘’’
}
}
}
}
使用之前配置的NodeJS节点node
执行结果如下:
Started by user zhujian
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /home/zj/.jenkins/workspace/test
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Tool Install)
[Pipeline] tool
Unpacking https://nodejs.org/dist/v13.1.0/node-v13.1.0-linux-x64.tar.gz to /home/zj/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node on Jenkins
$ /home/zj/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/bin/npm install -g hexo-cli gulp
npm WARN deprecated [email protected]: One of your dependencies needs to upgrade to fsevents v2: 1) Proper nodejs v10+ support 2) No more fetching binaries from AWS, smaller package size
/home/zj/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/bin/gulp -> /home/zj/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/lib/node_modules/gulp/bin/gulp.js
/home/zj/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/bin/hexo -> /home/zj/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/lib/node_modules/hexo-cli/bin/hexo
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/hexo-cli/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/gulp/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
- [email protected]
- [email protected]
added 382 packages from 508 contributors in 59.164s
[Pipeline] envVarsForTool
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Example)
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh - npm config ls
; cli configs
metrics-registry = “https://registry.npmjs.org/”
scope = “”
user-agent = “npm/6.12.1 node/v13.1.0 linux x64 ci/jenkins”
; node bin location = /home/zj/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/bin/node
; cwd = /home/zj/.jenkins/workspace/test
; HOME = /opt/tomcat
; “npm config ls -l” to show all defaults.
[Pipeline] sh
- node -v
v13.1.0 - npm -v
6.12.1 - gulp -v
CLI version: 2.2.0
Local version: Unknown - hexo -v
hexo-cli: 3.1.0
os: Linux 4.15.0-64-generic linux x64
node: 13.1.0
v8: 7.8.279.17-node.19
uv: 1.33.1
zlib: 1.2.11
brotli: 1.0.7
ares: 1.15.0
modules: 79
nghttp2: 1.39.2
napi: 5
llhttp: 1.1.4
openssl: 1.1.1d
cldr: 35.1
icu: 64.2
tz: 2019a
unicode: 12.1
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
在执行之前会先安装NodeJS,并安装预设置的应用