Fastlane failing tests on Jenkins

Viewed 2314

Im trying to run fastlane scan on Jenkins, the tests execute well, pass, but on the last part it seems to fail because it can't access or start the simulator :

[32;1m   Executed 337 tests, with 0 failures (0 unexpected) in 5.657 (5.702) seconds
[0m
2018-12-19 11:09:41.006 xcodebuild[87795:568022] [MT] IDETestOperationsObserverDebug: 34.991 elapsed -- Testing started completed.
2018-12-19 11:09:41.006 xcodebuild[87795:568022] [MT] IDETestOperationsObserverDebug: 0.000 sec, +0.000 sec -- start
2018-12-19 11:09:41.007 xcodebuild[87795:568022] [MT] IDETestOperationsObserverDebug: 34.991 sec, +34.991 sec -- end
2018-12-19 11:09:41.007 xcodebuild[87795:568022] Error Domain=IDETestOperationsObserverErrorDomain Code=6 "Early unexpected exit, operation never finished bootstrapping - no restart will be attempted" UserInfo={NSLocalizedDescription=Early unexpected exit, operation never finished bootstrapping - no restart will be attempted, NSUnderlyingError=0x7fa957d4a580 {Error Domain=IDETestOperationsObserverErrorDomain Code=5 "Test runner exited before starting test execution." UserInfo={NSLocalizedDescription=Test runner exited before starting test execution., NSLocalizedRecoverySuggestion=If you believe this error represents a bug, please attach the log file at /Users/admin/.jenkins/workspace/app/jenkins_build/app/logs/App Development.test_result/3_Test/Diagnostics/App-C8F63971-F551-4B88-9B36-2CD1895231B9/Lassie-55B9D4CF-E286-4D7E-9C3D-2F9EF57C9E2B/Session-Lassie-2018-12-19_110906-AgsuGb.log}}}

Testing failed:
App Development.app (92694) encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted. (Underlying error: Test runner exited before starting test execution.))
** TEST FAILED **

The weird part is: if it try to run the same command in shell, it works just fine. Already tried to restart and reset all simulators before starting the build, changed Always embed swift standard libraries to No, disabled parallel testing, but nothing works...

[EDIT]: Added Xcode build log:

12:13:25.326 xcodebuild[4767:695436] <DVTiPhoneSimulator (0x7ff3b2a46860), iPhone 7, unknown class, 11.0.1 (15A8401), 5BDE8E89-5FC4-47FF-860A-EDBE34C64EED> got death notice for pid 9688, removing from SimulatorSessionMap
12:13:25.326 xcodebuild[4767:695436] <DVTiPhoneSimulator (0x7ff3b2a46860), iPhone 7, unknown class, 11.0.1 (15A8401), 5BDE8E89-5FC4-47FF-860A-EDBE34C64EED> claim LaunchSessionClaim_0x7ff3b50bab40 on simulator was relinquished
12:13:25.327 xcodebuild[4767:695436] <DVTiPhoneSimulator (0x7ff3b2a46860), iPhone 7, unknown class, 11.0.1 (15A8401), 5BDE8E89-5FC4-47FF-860A-EDBE34C64EED> claim LaunchSessionClaim_0x7ff3b50bab40 on simulator was relinquished
12:13:25.724 xcodebuild[4767:695436] <IDETestOperationCoordinator: 0x7ff3b5260130> finished receiving data from testing launch session
12:13:25.724 xcodebuild[4767:695436] <IDETestOperationCoordinator: 0x7ff3b5260130>: _considerFlushingDelegateBlockQueue - nothing to flush
12:13:32.328 xcodebuild[4767:695436] Test operation failure: Test runner exited before starting test execution.
12:13:32.328 xcodebuild[4767:695436] _finishWithError:Error Domain=IDETestOperationsObserverErrorDomain Code=5 "Test runner exited before starting test execution." UserInfo={NSLocalizedDescription=Test runner exited before starting test execution.}

[EDIT]More details here :

https://github.com/fastlane/fastlane/issues/13956

Here is my jenkinsfile:

#!groovy
import groovy.json.JsonSlurperClassic
import hudson.model.*

node() {
  echo env.BUILD_NUMBER
  env.PATH = "/Users/admin/.rvm/xgems/ruby-2.4.1/bin:/Users/admin/.rvm/gems/ruby-2.4.1@global/bin:/Users/admin/.rvm/rubies/ruby-2.4.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/admin/.rvm/bin"
  sh "source ~/.bash_profile"
  currentBuild.result = "SUCCESS"

    echo "+++branch: ${env.branch}"
    echo "+++upload: ${env.upload}"
    echo "+++commit: ${env.commit}"
    echo "+++lane: ${env.lane}"
    echo "+++ statusUrl: ${env.statusUrl}"
    echo "+++ commentUrl: ${env.commentUrl}"
    echo "+++ gitToken: ${env.GIT_TOKEN}"

   buildStarted()
   runUnitTests("", env.branch)
   buildFinal()
  }

  def runUnitTests(lane, branch) {
    bundleInstall()
    checkout(lane, branch)
    cleanEnvironment()
    cleanFolders()
    cocoapods()
    unitTests()
  }

  def bundleInstall() {
    sh 'bundle install'
  }

  def cleanEnvironment() {
    stage('Prepare environment') {
      prepareEnvironment()
    }
  }

  def unitTests() {
    stage('UnitTests') {
      sh 'fastlane ios unit_tests --verbose'
    }
  }

  def cocoapods() {
    stage('cocoapods') {
      sh 'fastlane install_intelligent_dependencies'
    }
  }

  def prepareEnvironment() {
      KEYCHAIN="/Users/admin/Library/Keychains/jenkins.keychain-db"
      sh "security -v list-keychains -s ${KEYCHAIN}"
      sh "security -v unlock-keychain -p tests ${KEYCHAIN}"
      sh "security set-keychain-settings -t 3600 -l ${KEYCHAIN}"
  }

  def cleanFolders() {
    stage('Clean folders') {
        sh "rm -rf /Users/admin/.jenkins/workspace/lassie/jenkins_build/"
        sh "rm -rf /Users/admin/.jenkins/workspace/lassie/output/"
        sh "rm -rf /Users/admin/.jenkins/workspace/lassie/DerivedData/"
    }
  }

  def checkout(lane, branch) {
    stage('Checkout') {
      def branchToCheckout = ""
      if (lane == "appstore") {
        branchToCheckout = "origin/master"
      } else {
        branchToCheckout = "origin/${branch}"
      }
      checkout([
              $class                           : 'GitSCM',
              branches                         : [[name: branchToCheckout]],
              doGenerateSubmoduleConfigurations: false,
              extensions                       : [],
              submoduleCfg                     : [],
              userRemoteConfigs                : [
                      [credentialsId: '0000000-0000-0000-0000-00000000000',
                       url          : 'https://github.com/doghero/lassie.git']
              ]
      ])
    }
  }

  def updateStatus(gitStatus, message) {
    sh "curl -X POST -H 'Content-Type: application/json' " +
            "-H 'Authorization: token ${env.GIT_TOKEN}' ${env.statusUrl} " +
            "-d '{\"state\": \"${gitStatus}\",\"target_url\": \"https://jenkinsurl.com/job/lassie\",\"description\": \"${message}\",\"context\": \"CI/Jenkins\"}'"
  }

  def commentGithub(message) {
      sh "curl -X POST -H 'Content-Type: application/json' " +
              "-H 'Authorization: token ${env.GIT_TOKEN}' ${env.commentUrl} " +
              "-d '{\"body\": \"${message}\"}'"
  }

  def buildStarted() {
    updateStatus("pending", "InProgress...")
  }

  def buildSuccess() {
    updateStatus("success", "The build succeeded!")
  }

  def buildError() {
    updateStatus("failure", "Build failed")
  }

  def buildFinal() {
    echo currentBuild.result
    if (currentBuild.result == 'SUCCESS') {
        buildSuccess()
        commentGithub("Coverage: "+ getCoverage())
    } else {
        buildError()
    }
  }

  def getCoverage() {
    coverage = sh(
          script: "cat '/Users/admin/.jenkins/workspace/lassie/jenkins_build/code-coverage/report.json' | jq '.coverage'",
          returnStdout: true
          )
    return coverage
  }
0 Answers
Related