0

So I'm trying to learn more about jenkins and I developed a shell script that execute the tests for my iOS project and generates a report. I set the script to exit as soon as failures are detected (Since this is the only way I know how to get the build to fail if the tests fail).

That's the reason why the reports were not being generated. Because I exit the script as soon as the tests failed. But I'm not familiar with how to get the build to fail, without exiting prior to the generation of the reports. What can I do to circumvent this? Here's my current shells script:

set -o pipefail && xcodebuild -project "Tests.xcodeproj" 
    -scheme "Testing" 
    -sdk "iphonesimulator12.2" 
    -destination "platform=iOS Simulator,OS=latest,name=iPhone 7" 
    test -only-testing:"UITests/UITests" 
    -resultBundlePath TestResults | xcpretty
xchtmlreport -r TestResults
Jay
  • 2,591
  • 1
  • 16
  • 28

3 Answers3

0

you can use

always() { //some code here }

section to specific stage OR pipeline. Put the report generation in that block. Refer to https://jenkins.io/doc/book/pipeline/syntax/#post-conditions

In freestyle project you can add Post-build action

Denys
  • 38
  • 8
0

Typically you would execute all your tests and report each test case state in a result file (in my case this is in JUnit format for Java/JavaScript). After all tests have run you publish the result file using an appropriate Jenkins plugin step (in my case junit).

Christopher
  • 1,103
  • 1
  • 6
  • 18
0

Pipeline/Workflow Job in Jenkins using fastlane: What I did, is I set the post block to run three different lanes depending on the the status of the build. The post block has sublocks called success, unstable and failure. The lanes in the post block's subblocks post a slack message with SUCCESS, UNSTABLE, or FAILED for the three possibilities (successful build and all tests pass, successful build and 1 or more tests fail, and unsuccessful build) respectively. I use danger gem to post test result summary back to my pull request in the repository's comments. See here --> https://www.jenkins.io/doc/book/pipeline/syntax/#post

duncwa
  • 149
  • 1
  • 7