Get exit status of Android Monkey tool in Jenkins pipline

182 views Asked by At

I'm running test on an Android device using the monkey tool. The problem is the Jenkins pipeline passes as SUCCESS even when monkey crashes the app. Is there a way to get the exit code from sh or the monkey tool and mark the stage as a FAILURE?

stage('monkeytest'){
    node('android'){
        git credentialsId: '731f2b68-2c6d-', url: 'https://mygitrepo.git', branch: 'master'
        sh './gradlew installDebug'
        sh '/android-sdk-linux/platform-tools/adb shell monkey -p com.my.package -c android.intent.category.LAUNCHER 10000'
    }
}
1

There are 1 answers

0
Amityo On BEST ANSWER

Use sh with returnStatus

result = sh('/android-sdk-linux/platform-tools/adb shell monkey -p com.my.package -c android.intent.category.LAUNCHER 10000', returnStatus : true)
if (result != 0) {
    // handle errors
}