Jenkins捕获异常

使用捕获异常的方法来实现这一步!

stage('单元测试') {

            steps {

                                echo "starting unitTest......"

                                script {

 try {

                                             checkout scm

                             def gradlePATH = "/var/jenkins_home/tools/hudson.plugins.gradle.GradleInstallation/gradle3.5"

                             dir(env.JOB_NAME){

                                            sh "cp ${WORKSPACE}/${k8sPath}/Jenkinsfile ."

                                            sh "${gradlePATH}/bin/gradle clean build -x test "

                                                        }       

                               }

catch (err){

echo "gradle构建出错了,请您检查错误信息"

exit 1

                                               }       

                                     }

                            }

你可能感兴趣的:(Jenkins捕获异常)