New: 2 environment variables that pinpoint your build failure!

Hey folks :waving_hand:

There’s a better way to diagnose build failures. Bitrise now exposes two new environment variables –

Key Value
$BITRISE_FAILED_STEP_TITLE The title of the Step that first fails in a build. In other words, the Step that sets the build status to Failed.
$BITRISE_FAILED_STEP_ERROR_MESSAGE The error message of the Step that first fails in a build.

Let’s take a look at examples:

Example 1: Send failed Step and error message via Slack message

This example demonstrates how to send a Slack message including the title of the failing Step and the error message if the build fails. In this example, the Xcode test step fails because an invalid simulator is specified.

Notice the usage of BITRISE_FAILED_STEP_TITLE and BITRISE_FAILED_STEP_ERROR_MESSAGE in the Slack message step.

workflows:
  run_tests:
    steps:
    - git-clone@8: {}
    - xcode-test@6:
        inputs:
        - project_path: "$BITRISE_PROJECT_PATH"
        - scheme: "$BITRISE_SCHEME"
        - destination: platform=iOS Simulator,name=Bitrise iOS default,OS=9.1
    - deploy-to-bitrise-io@2: {}
    - slack@4:
        run_if: "{{.IsBuildFailed}}"
        inputs:
        - workspace_slack_integration_id: "$SLACK_INTEGRATION_ID"
        - text: |-
            Failing step: $BITRISE_FAILED_STEP_TITLE
            Error: $BITRISE_FAILED_STEP_ERROR_MESSAGE

Below is the slack message when the above build would fail:

Example 2: Run a Step conditionally based on a failed Step

In this example, the workflow notifies iOS devs about Xcode test failures and platform engineers about other build failures.

Notice the run_if conditions in the Slack message steps.

workflows:
  run_tests:
    steps:
    - git-clone@8: {}
    - xcode-test@6:
        inputs:
        - project_path: "$BITRISE_PROJECT_PATH"
        - scheme: "$BITRISE_SCHEME"
        - destination: platform=iOS Simulator,name=Bitrise iOS default,OS=9.1
    - deploy-to-bitrise-io@2: {}
    - slack@4:
        run_if: "{{enveq \"BITRISE_FAILED_STEP_TITLE\" \"Xcode Test for iOS\"}}"
        inputs:
        - workspace_slack_integration_id: "$IOS_DEVS_SLACK_INTEGRATION_ID"
        - text: |-
            Xcode Test for iOS has failed with error:
            $BITRISE_FAILED_STEP_ERROR_MESSAGE
    - slack@4:
        run_if: "{{enveq \"BITRISE_FAILED_STEP_TITLE\" \"Xcode Test for iOS\" | not}}"
        inputs:
        - workspace_slack_integration_id: "$PLATFROM_ENGINEERS_SLACK_INTEGRATION_ID"
        - text: |-
            $BITRISE_FAILED_STEP_TITLE has failed with error:
            $BITRISE_FAILED_STEP_ERROR_MESSAGE

Xcode test failure Slack message (sent to $IOS_DEVS_SLACK_INTEGRATION_ID ):

Git clone step failure Slack message (sent to $PLATFROM_ENGINEERS_SLACK_INTEGRATION_ID):

That’s it. Comment below if you have questions. Happy building :package:

1 Like