简体   繁体   中英

Make build UNSTABLE if text found in console log using jenkinsfile (jenkins pipeline)

I am trying to login into an instance and check if the file test.txt is not empty, then echo .. make build unstable using the jenkins pipeline (jenkinsfile)But that's not working. I have this:

post {
        always {
          sh "ssh ubuntu@$Ip 'if [ -s test.txt ] ; then echo some text && cat test.txt'"
        currentBuild.result = 'UNSTABLE'
          }
        }

Instead of doing above, can I parse through the console log of the latest build to find something eg: some text and if that's found I want to make the build unstable

You need to return standard out from the script:

String stdOut = sh returnStdout: true, script: "ssh ubuntu@$Ip 'if [ -s test.txt ] ; then echo some text && cat test.txt'"

if (stdOut == "") {
   currentBuild.status = 'UNSTABLE'
}

Or, you could use returnStatus to return the exit code of the script. The documentation for the sh step can be found here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM