The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing


External Resources

More Info

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

The following guide helps you get up and running with our plugin for Jenkins CI:

What You'll Need

  • Access the IP range,, and from your Jenkins server
  • You may need to refer to the Jenkins documentation for assistance setting up a proxy

Important Steps for All Continuous Integration Configurations

When you are configuring your continuous integration platform to work with Sauce, always make sure to follow these steps:

  1. Update tests to reference the environment variables set by the plugin. See the topic on Setting Environment Variables for more information.
  2. Output the Sauce session ID to the standard output (stdout) to allow the Sauce plugin to associate test results to Sauce Jobs. See the topic on Outputting Session IDs to stdout for more information.

Installing the OnDemand Plugin

You can install the Sauce OnDemand plugin for Jenkins though the Jenkins Administration page. 

  1. In Jenkins, go to the Administration page
  2. Click Manage Jenkins
  3. Click Manage Plugins
  4. Click the Available tab
  5. In the list of plugins, find and select Sauce OnDemand Plugin
  6. Click Download now and install after restart
  7. In the plugin installation dialog, select Restart Jenkins when installation is complete and no jobs are running

The plugin file is fairly large, so download may take several minutes.

Configuring Sauce Labs Credentials

The Jenkins plugin provides an interface for storing your Sauce Labs authentication credentials as environment variables on the Jenkins server, one of our best practices for testing with Sauce. This allows you to reference your credentials without having to hardcode them into your tests. Because the plugin manages authentication at the global level, you can have multiple jobs running at the same time using these credentials. 

  1. After the plugin has installed and Jenkins has restarted, go to the Administration page in Jenkins
  2. Click Credentials

  3. You can click an existing domain or click Add domain

  4. Once in your domain of choice, click Add Credentials
  5. Under Kind, select Sauce Labs
  6. Enter the Username and API Access Key for your Sauce account
  7. Click OK to save

Your credentials are now saved, and you can now use them on a per-project basis. To do so:

  1. Go to the Administration page for one of your projects
  2. Click Configure
  3. Under Sauce Labs Options, you will see the credentials you have stored as options under Credentials

Setting Authentication Environment Variables in Your Tests

Once you've set up your authentication credentials as environment variables, you can refer to them in your tests like this:

WebDriver driver = new RemoteWebDriver(
            new URL("http://"+System.getenv("SAUCE_USERNAME")+":"+System.getenv("SAUCE_ACCESS_KEY")+"",

See Setting Desired Capabilities for Jenkins Projects for more information on using environment variables.

Versions Before 1.147

In versions of the plugin prior to 1.147, credential management is handled slightly differently. You will find credential management in the Manage Jenkins > Configure System section:

  1. Once the plugin is installed and Jenkins restarted, go to the Administration page in Jenkins
  2. Click Manage Jenkins > Configure System

  3. Under Sauce Support, enter the Username and API Access Key for your Sauce account

You can find the complete changelog for each version of the Jenkins Plugin at GitHub:

Configuring the Plugin to Use the European Data Center

If you are running jobs on our European data center, you have an option to use our Jenkins plugin to see all of the integrated results and reports. You can choose the data center you want to use by updating your credentials and then using those in your build configurations. 

What You'll Need

  • Use Sauce OnDemand Plugin version 1.182 or above in order to use the feature outlined here.

Updating Credentials

By default the Jenkins plugin will use your credentials the US data center, so you need to create a new set of credentials to use the EU data center. You should set a descriptive ID for the EU credentials to make them distinct from the US credentials, as this will make it easier to set up pipelines with the appropriate credentials.

  1. After the plugin has installed and Jenkins has restarted, go to the Administration page in Jenkins. 
  2. Click Credentials.

  3. You can click an existing domain, or click Add domain.

  4. Once in your domain of choice, click Add Credentials.
  5. Enter the Username and API Access Key for your Sauce account.  
  6. Select EU as a Sauce Data Center 
  7. Specify an ID that will be used to identify credentials within the pipelines setup.
    If the ID field is left blank it will be auto-generated. If you forget or don’t know which ID is associated with the EU credentials, you can use the Pipeline Script page to generate the script with the right ID for you

  8. Click Save.

Non-Pipeline Build Configuration

If you are using non-pipeline builds, select the correct credentials in the Sauce Labs menu within your build. 

  1. Select Configure.

  2. Go to Sauce Labs Options.
  3. Under Credentials, select the credentials with the (EU) suffix
  4. Click Save

Pipeline Build Configuration

For pipeline builds, use the credential ID you created for the European data center, as shown in this code example. 

Sample EU and Jenkins Pipelines Block
stage('Test') {
    sauce('sauceuser-EU') {
        sauceconnect(useGeneratedTunnelIdentifier: true, verboseLogging: true) {
            sh 'mvn test'


  1. http://"+System.getenv("SAUCE_USERNAME")+":"+System.getenv("SAUCE_ACCESS_KEY")+""
    This is an insecure example because calls are not using HTTPS.  Change "http" to "https".  Change ":80" to "443"
  2. "http:
    Even though port 80 is supported, all examples should specify "https" by default to ensure ondemand traffic is encrypted using TLS between customer site and Sauce Labs.