1

I have such stage definition in Jenkins Pipeline:

stage('iPhone 8, iOS 11.4') {
    steps {
        sh 'echo "Unit Tests for iPhone 8, iOS 11.4"'
        sh 'xcodebuild -scheme "[SCHEME]" -workspace [PROJECT].xcworkspace -configuration "Debug" test-without-building -destination "platform=iOS Simulator,name=iPhone 8,OS=11.4" -enableCodeCoverage YES | /usr/local/bin/xcpretty -r junit  --output ./build/reports/junit-11.4.xml'
    }
    post {
        failure {
            sh 'echo "${env.STAGE_NAME} failed"'
            notifyUnstableSlack(env.STAGE_NAME)
        }
    }
}

...

def notifyUnstableSlack(String stageName) {
    stageName = stageName ?: ''

    def color = '#FFFE89'
    def msg = "UNSTABLE: `${env.JOB_NAME}@${stageName}` #${env.BUILD_NUMBER}:\n${env.BUILD_URL}"
    slackSend(color: color, message: msg)
}

I try to send Slack notification when tests in this stage fail and stage gets status FAILED / UNSTABLE but nothing is sent.

I tried also unstable{} action in post{} block but this also did not sent any message to slack.

update: end of stage log:

Executed 52 tests, with 1 failure (0 unexpected) in 0.155 (0.162) seconds
2019-04-07 11:11:04.708 xcodebuild[8728:129932]  IDETestOperationsObserverDebug: Failure collecting logarchive: Test daemon protocol version 22 is too old to support log archive collection (minimum 26)
2019-04-07 11:11:04.710 xcodebuild[8728:124814] [MT] IDETestOperationsObserverDebug: 65.073 elapsed -- Testing started completed.
2019-04-07 11:11:04.710 xcodebuild[8728:124814] [MT] IDETestOperationsObserverDebug: 0.000 sec, +0.000 sec -- start
2019-04-07 11:11:04.710 xcodebuild[8728:124814] [MT] IDETestOperationsObserverDebug: 65.073 sec, +65.073 sec -- end

Failing tests:
    ProjectTests:
        ViewControllerTests.test_Geocoder_FetchesCoordinates()

Test session results and logs:
    /Users/Shared/Jenkins/Library/Developer/Xcode/DerivedData/Project-eicgdkjbrvpuddesfbyzlxovkhgp/Logs/Test/Test-Project-2019.04.07_11-09-59-+0200.xcresult

** TEST EXECUTE FAILED **
Paweł Madej
  • 1,229
  • 23
  • 42
  • To clarify your question. Is your post stage not called or is the post stage just not sending the slack message? – Michael Kemmerzell Apr 07 '19 at 09:23
  • @mkemmerz it looks like failure / unstable actions are not called because `sh 'echo "${env.STAGE_NAME} failed"'` is also not visible in log – Paweł Madej Apr 07 '19 at 09:35
  • What exit code does your xcodebuild return? Some programs return a zero even if the execution fails which Jenkins does not interpret as a failure. – Michael Kemmerzell Apr 07 '19 at 09:42
  • I've added log from this stage. Stage is marked green. – Paweł Madej Apr 07 '19 at 09:49
  • Your problem seems to be the same as mentioned in this question: https://stackoverflow.com/questions/7363459/how-to-get-the-return-value-of-xcodebuild - xcodebuild returns always a zero as exit code so Jenkins does not recognize the failure. Maybe try the 'xcodebuild ... | exit 1' mentioned in the linked question – Michael Kemmerzell Apr 07 '19 at 09:54
  • now I think if this problem is not caused by piping xcodebuild to xcpretty to format test results file? what do you think? – Paweł Madej Apr 07 '19 at 10:58
  • This could also be the cause of the problem, yes – Michael Kemmerzell Apr 07 '19 at 13:29

1 Answers1

0

I don't know if you already solve this issue, but to whoever is looking to solve this and is using XCPretty the documentation says to use this if running on CI

set -o pipefail && xcodebuild [flags] | xcpretty

https://github.com/xcpretty/xcpretty

This worked for me on jenkins