The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing

Insights

External Resources

More Info


Page tree
Skip to end of metadata
Go to start of metadata

In order to upload your apps from Microsoft App Center to a Sauce Labs data center you must create a post-build script in Microsoft App Center. Please note, if you're looking for the legacy solution please visit the Legacy Platform App Center Integration page.

What You'll Need

Creating the post-build Script

  1. Once you've linked your project source code to your app center project, create a script called appcenter-post-build.sh and add it to your project source code repository.
  2. If you're testing a cross-platform application (e.g. a react-native), add the following environment variables APP_NAME and BUILD_NAME.

    If you're building a single project (iOS or Android) ignore steps 2-4 and skip to step 5.

    #!/usr/bin/env bash
    APP_NAME="your.app.name"
    # You can find this name in the build logs of a previous project
    # for now we create an empty variable and change it based on the
    # project that is using this script
    BUILD_NAME="your.build.name"
  3. Set the correct app name based on the application platform.

    if [[ "$APPCENTER_XCODE_PROJECT" ]]; then
        APP_NAME="iOS.SauceLabs.Mobile.Sample.app.ipa"
        BUILD_NAME="SwagLabsMobileApp.ipa"
    else
        APP_NAME="Android.SauceLabs.Mobile.Sample.app.apk"
        BUILD_NAME="app-release.apk"
    fi
  4. You can optionally set a console message to appear in your App Center logs.

    echo "**************** PUBLISH APP TO SAUCELABS WITH THIS DATA ******************"
    echo "APP NAME                => $APP_NAME"
    echo "BUILD NAME              => $BUILD_NAME"
    echo "OUTPUT DIRECTORY        => $APPCENTER_OUTPUT_DIRECTORY"
    echo "PAYLOAD                 => $APPCENTER_OUTPUT_DIRECTORY/$BUILD_NAME"
  5. Now you can add the following command to push to the relevant data center that contains your target real device.

    Push to US Data Center
    curl \
      -F "payload=@$APPCENTER_OUTPUT_DIRECTORY/$BUILD_NAME" \
      -F name=$APP_NAME \
      -u "$SAUCE_USERNAME:$SAUCE_ACCESS_KEY"  'https://api.us-west-1.saucelabs.com/v1/storage/upload'
    Push to EU Data Center
    curl \
      -F "payload=@$APPCENTER_OUTPUT_DIRECTORY/$BUILD_NAME" \
      -F name=$APP_NAME \
      -u "$SAUCE_USERNAME:$SAUCE_ACCESS_KEY"  'https://api.eu-central-1.saucelabs.com/v1/storage/upload'

    If you need to retrieve a specific build, or information regarding the build that ran during this operation, you can use the Application Storage API.

  6. Here's the full script in the Sauce Labs sample mobile app repo:

    App Center Post Build Script
    #!/usr/bin/env bash
    ####################################################################################################
    # This script has been created for a React Native project which can build
    # AND Android, AND iOS apps. If you build a single project (OR Android OR iOS
    # then you don't need the APP_NAME, BUILD_NAME and APPCENTER_XCODE_PROJECT logic.
    #
    # In order for this script to work you need to:
    # - go to AppCenter
    # - go to your project
    # - Configure your project
    # - Then you should see the post-script, then SAVE it, otherwise it will not work
    # See src: https://github.com/MicrosoftDocs/appcenter-docs/issues/53
    ####################################################################################################
    
    ##
    # Create an empty variable, this will be set later
    #
    APP_NAME=""
    
    ##
    # You can find this name in the build logs of a previous project
    # for now we create an empty variable and change it based on the
    # project that is using this script
    #
    BUILD_NAME=""
    
    ##
    # Set the correct app name based on the platform
    #
    if [[ "$APPCENTER_XCODE_PROJECT" ]]; then
        APP_NAME="iOS.SauceLabs.Mobile.Sample.app.ipa"
        BUILD_NAME="SwagLabsMobileApp.ipa"
    else
        APP_NAME="Android.SauceLabs.Mobile.Sample.app.apk"
        BUILD_NAME="app-release.apk"
    fi
    
    ##
    # Add some extra logs
    #
    echo "**************** PUBLISH APP TO SAUCELABS WITH THIS DATA ******************"
    echo "APP NAME                => $APP_NAME"
    echo "BUILD NAME              => $BUILD_NAME"
    echo "OUTPUT DIRECTORY        => $APPCENTER_OUTPUT_DIRECTORY"
    echo "PAYLOAD                 => $APPCENTER_OUTPUT_DIRECTORY/$BUILD_NAME"
    
    #
    # For this project we push to both DCs
    #
    
    #
    # Push to US
    #
    curl \
      -F "payload=@$APPCENTER_OUTPUT_DIRECTORY/$BUILD_NAME" \
      -F name=$APP_NAME \
      -u "$SAUCE_USERNAME:$SAUCE_ACCESS_KEY"  'https://api.us-west-1.saucelabs.com/v1/storage/upload'
    
    #
    # Push to EU
    #
    curl \
      -F "payload=@$APPCENTER_OUTPUT_DIRECTORY/$BUILD_NAME" \
      -F name=$APP_NAME \
      -u "$SAUCE_USERNAME:$SAUCE_ACCESS_KEY"  'https://api.eu-central-1.saucelabs.com/v1/storage/upload'