3.3.1、按照应用
https://nodejs.org/dist/v14.15.4/node-v14.15.4-linux-x64.tar.xz
tar xvf node-v14.15.4-linux-x64.tar.xz
mv node-v14.15.4-linux-x64 node
3.3.2、配置环境变量
export NODE_HOME=/usr/axyh/node
export PATH=$JAVA_HOME/bin:$MVN_HOME/bin:$ANT_HOME/bin:$NODE_HOME/bin:$PATH
3.3.3、验证
[root@centos1 axyh]# node -v
v14.15.4
[root@centos1 axyh]# npm -v
6.14.10
3.3.4、按照插件、配置全局工具
https://mirrors.tuna.tsinghua.edu.cn/jenkins/plugins/nodejs/latest/
3.3.5、本地环境安装
npm install -g npm
3.3.6、编写jenkinsfile
#!groovy
String buildShell = "${env.buildShell}" //引用参数
pipeline {
agent {
node {
label "master" //构建主机
}
}
stages {
stage("mvnBuild") {
steps {
script {
mvnHome=tool "m2" //引用工具
sh "${mvnHome}/bin/mvn ${buildShell}" //引用参数变量
}
}
}
stage("antBuild") {
steps {
script {
try{ //防止异常终止执行
AntHome=tool "ant" //引用工具
sh "${AntHome}/bin/ant ${buildShell}" //引用参数变量
} catch(e){
println(e)
}
}
}
}
stage("npmBuild") {
steps {
script {
NpmHome=tool "NPM" //引用工具
sh "${NpmHome}/bin/npm ${buildShell}" //引用参数变量
}
}
}
}
}