[Jenkins] Warning in pipeline

It is usual when running pipeline, it will expect to continue even execute failure. Previously, need to use try..catch and change currentBuild.currentResult to unstable (Originally it can set as SUCCESS, FAILURE, UNSTABLE). Since Jenkine 2.26, you can use statement unstable to identify it.

This example will run command gradle test failure to mark warning in pipeline.

script {
    try {
        sh """
        gradle test
        """
    } catch(Exception e) {
        unstable "Error found in unit test. Message: "+e.getMessage()
    } finally {
        try {
            junit "build/test-results/test/*.xml"
        } catch(Exception e) {
        unstable "Error found when export JUnit report to Jenkins. Message: "+e.getMessage()
        }
    }
}

 

About C.H. Ling 260 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.