Need to continue with CI script when xcodebuild test fails

Need to continue with CI script when xcodebuild test fails

Hi Guys! I am running a test build for my XCode project in a runner, and I am having the following behaviour. First of all, this is my test build in the .gitlab-ci.yml file:

test_build:
  stage: test
  tags:
  - macos
  inherit:
    default: false
  needs:
  - job: build_job
    artifacts: true
  script:
  - echo testing build
  - xcodebuild test -scheme ProjectTests -resultBundlePath TestResults -destination 'platform=iOS Simulator,name=iPhone 11,OS=13.7'
  - echo get report
  - xchtmlreport -r TestResults
  allow_failure: true
  dependencies:
    - build_job
  artifacts:
    when: always
    paths:
      - index.html
    reports:
      junit: index.html
  • The problem that I am having is that when xcodebuild test command fails because of a failing test, the script won’t continue and therefore, xchtmlreport won’t be executed. I already tried writing both commands in the same line separated by a semicolon, so xchtmlreport should be executed even if xcodebuild fails, but it didn’t work either.
    I need that xchtmlreport command runs no matter the result of xcodebuild test because obviously I need the report for both the error and the success cases.

Here is also a screenshot of the job’s log:

Thanks for your time! Hope you could help me!

The user crossposted this question here: Need to continue with CI script when xcodebuild test fails (#273402) · Issues · GitLab.org / GitLab · GitLab

The solution is to instruct bash to always use a “successful” exit-code.

Example:

- xcodebuild test ... || exit_code=$?
- xchtmlreport ...
- exit $exit_code

or

- xcodebuild test ... || true
- xchtmlreport ...