Jenkins /凹槽-动态阶段显示所有阶段均失败

时间:2019-02-14 14:02:52

标签: jenkins pipeline devops git-stage groove

我用凹槽脚本重新读取了一个外壳脚本文件/tmp/cmd_list.sh并创建了一个动态平台来构建。

/tmp/cmd_list.sh的内容为:

ls
pwd
aaaaaa
who

仅“ aaaaaa” mut无法执行(退出代码127)。 我的问题是,所有阶段都标记为失败,但是当我看到日志时,诸如“ ls”,“ pwd”和“ who”之类的命令可以正常工作,返回码为0。

我试图对盒子的舞台状态进行调整,但没有成功... 我的Groove脚本(Jenkinsfile):

import hudson.model.Result

node('master') {

    stage ('\u27A1 Checkout'){
        sh "echo 'checkout ok'"
    }

    def BUILD_LIST = readFile('/tmp/cmd_list.sh').split()
    for (CMDRUN in BUILD_LIST) {

        def status;

        try {
            node{
                stage(CMDRUN) {

                    println "Building ..."

                    status = sh(returnStatus: true, script: CMDRUN )
                    println "---> EX CODE: "+ status

                    if(status == 0){
                        currentBuild.result = 'SUCCESS'
                        currentBuild.rawBuild.@result = hudson.model.Result.SUCCESS
                    }
                    else{ 
                        currentBuild.result = 'UNSTABLE'
                        currentBuild.rawBuild.@result = hudson.model.Result.UNSTABLE
                    }

                    def e2e = build job:CMDRUN, propagate: false

                }
            }
        }
        catch (e) {
            println "===> " + e
            currentBuild.result = 'UNSTABLE'

            println "++++> EX CODE: "+ status

            if(status == 0){ 
                println "++++> NEW STATUS: "+ status
                currentBuild.rawBuild.@result = hudson.model.Result.SUCCESS
                currentBuild.result = 'SUCCESS'
            }
            else{
                println "++++> NEW STATUS: "+ status
                currentBuild.rawBuild.@result = hudson.model.Result.UNSTABLE
            }

        }


    }

}

结果是: Stage failed list   有人可以帮助我显示正确的状态吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

我更改了脚本,现在可以按预期工作了!

新代码:

node('master') {

    def build_ok = true

    stage ('\u27A1 Checkout'){
        sh "echo 'checkout ok'"
    }


    def BUILD_LIST = readFile('/tmp/cmd_list.sh').split()
    for (CMDRUN in BUILD_LIST) {

        try {
            stage(CMDRUN) {

                println "Building ..."
                sh CMDRUN

            }

        }
        catch (e) { build_ok = false }

    }


    if(build_ok) { currentBuild.result = "SUCCESS" }
    else { currentBuild.result = "FAILURE" }

}

expected Result