步骤未在jenkins管道中运行,并且退出代码-2

问题描述 投票:0回答:1

Reulst:

npm配置集注册表https://registry.npm.taobao.org

npm配置集'sass-binary-site = http://npm.taobao.org/mirrors/node-sass'

进程显然从未在/ home / jenkins / workspace / demo_nodejs @ tmp / durable-a15f6a06中启动

错误:脚本返回退出代码-2

完成:失败

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

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”之后不久。

jenkins pipeline
1个回答
0
投票

您是否尝试连接到Pod并从中运行NPM命令?您可以在失败之前添加一个睡眠步骤,然后连接到pod并在pod中运行npm命令。

© www.soinside.com 2019 - 2024. All rights reserved.