首页 > 解决方案 > 步骤不在詹金斯管道中运行,并退出代码-2

问题描述

结果:

npm config set registry https://registry.npm.taobao.org

npm config set 'sass-binary-site=http://npm.taobao.org/mirrors/node-sass'

process apparently never started in /home/jenkins/workspace/demo_nodejs@tmp/durable-a15f6a06

ERROR: script returned exit code -2

Finished: FAILURE

还有我的管道脚本(秘密是我的秘密信息):

def registry = SECRET
def library = 'demo'
def name = 'nodejs_demo'
podTemplate(){
    node('nodejs') { // my podtemplate is defined in global config, and can run well.
        echo 'ready go'
        def path = pwd()
        def branch_ = ''
        def author = ''
        def version = ''
        def image
        branch_ = 'master'
        echo 'branch_ = ' + branch_
        // clone git 
        stage("clone code") {
            git credentialsId: SECRET, branch: branch_, url: SECRET
            sh 'git log --no-merges --pretty=format:"%an" -1 > author.txt'
            sh 'git log --no-merges --pretty=format:"%h" --abbrev=8 -1 > version.txt'
            sh 'url=`cat .git/config|grep git`&&url=${url##*/}&&echo ${url%.*} > name.txt'
            author = readFile("author.txt")
            version = readFile("version.txt")
            image = "${registry}/${library}/${name}"
            echo "${image}"
            echo 'clone code complete'
        }
        # enter container.
        container('nodejs') {
            stage("nodejs install") { // my Step
                sh 'npm config set registry https://registry.npm.taobao.org'
                sh 'npm config set sass-binary-site=http://npm.taobao.org/mirrors/node-sass'
                sh 'npm install' // not execute it.
            }
            stage("nodejs build") {
                sh 'npm run build'
            }
            stage('copy dockerfile') {
                input "Exit"
            }
        }
    }
}

地位:

“npm install”或“npm build”在我的 jenkinsfile 中定义。

  1. 当脚本运行“npm config” 在我的 jenkinsfile 中,下一步是“npm install”,但它没有运行,我的工作流程是退出。

  2. 我使用相同的 jenkinsfile,如果我很幸运,我可以收到成功消息。

  3. 错误将在其他位置发生,例如在“npm install”之后或“npm build”之后很快。

标签: jenkinsjenkins-pipeline

解决方案


请检查您的全局配置或节点配置中是否有空的环境变量。


推荐阅读