I'm searching for a way to retry run failed Android instrumented tests or called integration tests/ui tests. I think there could have 3 ways of doing this.
Retry with Jenkins stage script -> retrieve all failed tests and perform them again with run gradle command
./gradlew clean app:connectedVariantNameAndroidTest-> I didn't try this approach yet.Plugins: I tried Gordon, however, its minimum Java support version is 17, which is not aligned with our CI machine (Java 11)
Implementation in code as some helper class: Tried this post -> The retry didn't happen when the instrumented test failed.
I think retrying on instrumented failed tests is commonly used in test automation since instrumented tests are flaky and easy to fail. Please help if you have any ways to accomplish this.
You can restart declarative pipeline from any stage. It will works if you keep build workspace and if errors rised outside pipeline execution, not in code or test or dependencies. In that case you need to update your sources. For some cases you may need to use
gradle(dotnet mvn etc ...) cleanYou can place it inpost{always {}}step if yours code must be recompiled.Examples
Jenkins side
jenkins post states
Pipeline:
output:
Replay stage:
Replay output:

Explanation:
Look in post stage comments You can see that integration test stage runs in same env. That meens you dont need to restart build stage for binary compilation
You can compile simple and advanced example if you wish. But i think it will be overkill
Gradle side
You may add some logic in your pre&post wrappers to check test status and replay cases at some conditions. Unfortunately, the gradle test retry plugin does not support Android Instrumentation tests.