Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to attach tests reports to slack notification through Fastlane

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 ?

like image 992
Ivelius Avatar asked Nov 02 '18 15:11

Ivelius


People also ask

What does testproject do with slack notifications?

With TestProject you now have the option to receive easy to read summary reports of your test automation job executions with Slack notifications. Whether your job was executed manually, by a schedule or from a CI tool build like Jenkins.

How do I trigger the Fastlane?

To trigger fastlane, just add the command you would usually run from your terminal: If you want to post test results on Slack, Hipchat or other team chat client, check out the available fastlane actions. If you're using Slack, this is already built-into the default run_tests action, just provide your Slack URL:

How do I run unit tests or Ui tests using Fastlane?

To run your unit tests or UI tests using fastlane, add the following to your Fastfile Additionally you can specify more options for building and testing your app, for example To run iOS tests using fastlane on a Continuous Integration service, check out the Continuous Integration docs.

How do I force Slack to flash when I receive notifications?

Select Preferences from the menu to open your notification preferences. Scroll down to Flash window when a notification is received and select Always. Tip: Selecting the preference Always will also keep the Slack icon in the taskbar when the app window is closed.


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
like image 99
Akif Avatar answered Oct 16 '22 12:10

Akif