How to attach tests reports to slack notification through Fastlane

Viewed 805

I can't find a solution for a pretty trivial (IMHO) setup.

In my iOS application I use Fastlane to run tests through a scan command. This generates a pretty useful xpretty tests report HTML file.

I would like to send a slack notification at the end of the tests with attached link to my generated HTML tests results file. I am using a Gitlab with a runner installed on a minimac to run my CI pipeline.

So far I cannot find a solution to this setup. Can someone point me to the right direction ?

1 Answers

I hope you already found a solution in the latest 2 years. As pointed in the comments, you can use the webhooks of Slack. And then you can run the slack command in your steps like this:

platform :ios do
  before_all do
    ENV["SLACK_URL"] = "https://hooks.slack.com/services/T0A6LPW3A/B5B2SBA13/etc..."
  

  desc "Tests, builds and uploads to iTunesConnect"
  lane :appstore do

    ENV["LANE_NAME"] = "Flicker"
    ENV["BUNDLE_ID"] = "com.epri.fem"
    ENV["SCHEME_NAME"] = ENV["LANE_NAME"]
    ENV["TEAM_NAME"] = "Electric Power Research Institute"

    runConfiguration()

  end

  def runConfiguration()

    slack(
    message: ENV["LANE_NAME"] + ") Incoming from branch " + sh("git rev-parse --abbrev-ref HEAD") + " - " + sh("git rev-parse HEAD"),
    slack_url: ENV["SLACK_URL"]
    )

    sigh(team_name: ENV["TEAM_NAME"],
         app_identifier: ENV["BUNDLE_ID"],
         skip_certificate_verification: true) # Update Provisioing Profiles / Code Signing

    slack(
    message: "Finished updating provisioing profiles",
    default_payloads: [],
    slack_url: ENV["SLACK_URL"]
    )

    scan(
    scheme: ENV["SCHEME_NAME"],
    slack_url: ENV["SLACK_URL"]
    ) # run tests

    gym(scheme: ENV["SCHEME_NAME"],
        clean: true) # build the app

    slack(
    message: "Finished building app",
    default_payloads: [],
    slack_url: ENV["SLACK_URL"]
    )

    pilot(skip_submission: true,
          team_name: ENV["TEAM_NAME"])  #upload to test flight

    slack(
    message: "Finished archiving and uploading to iTunesConnect",
    default_payloads: [],
    slack_url: ENV["SLACK_URL"]
    )

  end

  error do |lane, exception|
    slack(
    message: exception.message,
    default_payloads: [],
    slack_url: ENV["SLACK_URL"]
    )
  end
Related