天天看點

jenkins中/usr/bin/env: node: No such file or directory

兩種方式解決:

第一種:建立node軟連接配接到/usr/sbin目錄下

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

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....."
            }
        }
    }

}      

繼續閱讀