shell jenkins pipeline应该在出现“Compiled with the following type errors”这句话后失败

lawou6xi  于 2023-08-07  发布在  Shell
关注(0)|答案(1)|浏览(94)

嗨,我需要帮助来写Jenkins管道,如果“编译以下类型错误”这句话发生。管道应中止
我尝试了if(sh(npm run build:dev).exitCode!= 0)则{

echo 'npm build failed with compilation error'
               }
               else
                {
                     echo 'npm build succeeded'
               }
               fi

字符串
但我不确定它是工作还是不显示syntex错误“{”意外(期待“然后”)

sh7euo9m

sh7euo9m1#

您可以(或许应该)改用try catch块。

node {
    stage('example'){
        try {
            // npm install
            echo 'npm build succeeded'
        } catch (exc) {
            echo 'npm build failed with compilation error'
            throw exc
        }
    }
    
    stage('Next'){
        /* Will run if npm install works.
           Won't run if it fails as because of "throw exc"
        */
        echo "This was next"
    }
}

字符串
相关文件

相关问题