两种方式解决:

第一种:创建node软连接到/usr/sbin目录下

ln -s /application/node-v14.2.0-linux-x64/bin/node /usr/sbin/node

第二种:

在执行sh时添加环境变量

pipeline{
    agent {
        node { label "master" }
    }
    parameters{
        choice(choices: ["-v","build"],description: "npm",name: "buildShell")
    }
    stages{
        stage("npm构建"){
            steps{
                script{
                    nodejs_home = tool "NPM"
                    sh "export PATH=\$PATH:${nodejs_home}/bin && ${nodejs_home}/bin/npm ${buildShell}"
                }
            }
        }
    }
}
def buildTools = ["web": "/usr/local/node-v14.16.1-linux-x64"]

pipeline {
	agent { label  "build" }	
    options {
		skipDefaultCheckout true
	}

	stages {
		stage("GetCode"){
			steps{
				script{
                       checkout([$class: 'GitSCM', 
                          branches: [[name: "${branchName}"]], 
                          extensions: [], userRemoteConfigs: 
                          [[credentialsId: "${credentialsId}", 
                          url: "${srcUrl}"]]])
				}
			}
			
		}

		stage("Build"){
			steps {
				script {
				sh """
				export PATH=\$PATH:${buildTools["web"]}/bin 
				${buildTools["web"]}/bin/npm install 
				${buildTools["web"]}/bin/npm run build
				"""
				}
			}
		}

	}

	post {
		always {
			script{
				echo "always......"

			}
		}

		success {
			script {
				echo "success....."
			}
		}
	}

}

 

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐