当测试失败时,未触发阶段中的Jenkins Pipeline后期行动

ebdffaop  于 2022-12-22  发布在  Jenkins
关注(0)|答案(1)|浏览(194)

我在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)
}

我尝试在此阶段中的测试失败时发送Slack通知,并且此阶段的状态为FAILED / UNSTABLE,但没有发送任何通知。
我还尝试了post{}块中的unstable{}操作,但这也没有向slack发送任何消息。

**更新:**阶段日志结束:

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 **
uajslkp6

uajslkp61#

我不知道您是否已经解决了这个问题,但是对于希望解决这个问题并且正在使用XCPretty的任何人,文档都说如果在CI上运行,则使用XCPretty

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

https://github.com/xcpretty/xcpretty
这对我对付Jenkins很有效

相关问题