Skip to content

Instantly share code, notes, and snippets.

@santiycr
Last active December 14, 2015 19:49
Show Gist options
  • Save santiycr/5139565 to your computer and use it in GitHub Desktop.
Save santiycr/5139565 to your computer and use it in GitHub Desktop.
A small bash script to download and start Sauce Connect as part of a Travis Build.
#!/bin/bash
# Setup and start Sauce Connect for your TravisCI build
# This script requires your .travis.yml to include the following two private env variables:
# SAUCE_USERNAME
# SAUCE_ACCESS_KEY
# Follow the steps at https://saucelabs.com/opensource/travis to set that up.
#
# Curl and run this script as part of your .travis.yml before_script section:
# before_script:
# - curl https://gist.github.com/santiycr/5139565/raw/sauce_connect_setup.sh | bash
CONNECT_URL="http://saucelabs.com/downloads/Sauce-Connect-latest.zip"
CONNECT_DIR="/tmp/sauce-connect-$RANDOM"
CONNECT_DOWNLOAD="Sauce_Connect.zip"
READY_FILE="connect-ready-$RANDOM"
# Get Connect and start it
mkdir -p $CONNECT_DIR
cd $CONNECT_DIR
curl $CONNECT_URL > $CONNECT_DOWNLOAD
unzip $CONNECT_DOWNLOAD
rm $CONNECT_DOWNLOAD
java -jar Sauce-Connect.jar --readyfile $READY_FILE \
--tunnel-identifier $TRAVIS_JOB_NUMBER \
$SAUCE_USERNAME $SAUCE_ACCESS_KEY &
# Wait for Connect to be ready before exiting
while [ ! -f $READY_FILE ]; do
sleep .5
done
@patcon
Copy link

patcon commented Mar 27, 2013

You should add some logic around TRAVIS_SECURE_ENV_VARS to skip the download and run if we don't have access to the encrypted credentials :)
http://about.travis-ci.org/docs/user/ci-environment/#Environment-variables

@headrevision
Copy link

This script becomes obsolete with the Sauce Connect build addon for Travis CI: http://about.travis-ci.org/docs/user/addons/#Sauce-Connect

@andyli
Copy link

andyli commented Feb 21, 2014

Seems like gists are now being served with a different host. To make the download more robust, there should be -L for curl, such that it follows redirect:

curl https://gist.github.com/santiycr/5139565/raw/sauce_connect_setup.sh -L | bash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment