Skip to main content
Introducing support for Selenium 4 and its BiDi APIs on BrowserStack Automate! Learn More!

Integrate BrowserStack Automate with Jenkins

Integrate your Selenium test suite with Jenkins and the BrowserStack Selenium grid using our plugin.


Jenkins is an open-source Continuous Integration (CI) server, which automates the build and deploy process of your web applications. By running your Selenium test suite in Jenkins, you also automate testing as part of the build process. Add BrowserStack to the mix, and your web apps can be tested across 3000+ real devices and desktop browsers. BrowserStack lets you integrate your Selenium tests with Jenkins using a plugin that connects your Jenkins CI server to the BrowserStack Selenium Grid.

Use the BrowserStack Jenkins plugin to:

  • Configure your BrowserStack credentials for your Jenkins jobs.
  • Set up and tear down the BrowserStack Local binary for testing internal, development, and staging environments.
  • Embed BrowserStack test results, including video, logs, and screenshots in your Jenkins job results.


You need the following set up before you begin:

  • An existing Jenkins CI server (version 1.653+)
  • A BrowserStack account

Installing the Jenkins plugin

To run your Selenium tests with Jenkins on BrowserStack, you will first need to download our Jenkins plugin. Before installing the plugin, ensure you have the necessary privileges to administer your Jenkins installation. We recommend doing this when there are no active build jobs running on Jenkins.

  1. Click on Manage Jenkins > Manage Plugins.
  2. Click on the Available tab.
  3. In the search box type BrowserStack.
  4. Choose BrowserStack from the list of available plugins. choose BrowserStack from the list of available plugins
  5. Check the box and install the plugin.
  6. Once the plugin has been successfully installed you will be able to see it in the list of Installed plugins. BrowserStack plugin listed in available plugins on jenkins
Note: If the BrowserStack plugin doesn’t show up in the list of Available plugins, click on the Check Now button to force Jenkins to pull the latest available plugins from Jenkins update center.

Configuring BrowserStack credentials

Once you’ve installed the plugin, you will need to configure your BrowserStack credentials to complete the integration between Jenkins and your Selenium Webdriver tests. This can be done by either using Jenkins UI or using a Jenkinsfile.

Follow these steps to configure BrowserStack inside Jenkins:

  1. Go to Manage Jenkins > Configure System.
  2. Under the BrowserStack section, click on the Add button next to BrowserStack Credentials. Click on the add button for adding BrowserStack credentials
  3. Enter your BrowserStack Username and Access Key which you can find on your BrowserStack Account Settings page. Enter username and access key for Browserstack plugin
  4. Once you add your credentials, Jenkins generates an unique CredentialD which is used in the Jenkinsfile, this ID is changed every time you add your credentials. Browserstack automate jenkins plugin - Manage Credentials
  5. Inorder to avoid new CredentialD, you can provide custom credentialD while adding credentials. Hence, you will not be required to update Jenkins file every time. Follow the below steps to add custom CredentialID.

    a. Click on Advanced as highlighted in the following figure: Focused advanced button in Jenkins Credentials Provider Form

    b. Add the custom ID in the ID field: Image showing Jenkins Credential Provider form where the text box and label around ID are highlighted Save your changes.

Follow these steps to configure BrowserStack inside Jenkins:

  1. Go to the Pipeline project > Configure.
  2. Under the Pipeline section, click Pipeline Syntax
  3. Select the browserstack:BrowserStack in the Sample Step dropdown menu and click Add to set BrowserStack credentials in Jenkins. set browserstack credentials in jenkins file
  4. Add your BrowserStack username and access key in Jenkins Credentials Provider: Jenkins window and click Add as shown below: Adding browserstack credentials on jenkins This will set your BrowserStack Username and Access_Key in Jenkins.

Once you add your credentials as mentioned above, Jenkins generates an ID which is used in the Jenkinsfile.

From the Jenkins home page, click on Manage Jenkins then Manage Credentials. You can copy the ID for BrowserStack credentials. Browserstack automate jenkins plugin - Manage Credentials

Use the sample code in your Jenkinsfile:

browserstack(credentialsId: '<browserstackCredentialsID>') {
    // code for executing test cases

The above Jenkinsfile code block can also be generated with the help of Pipeline Syntax generator tool available in Jenkins.

To generate the step snippet with Snippet Generator:

  1. Navigate to the Pipeline Syntax from a configured Pipeline, or at <jenkins-ip>:<port>/pipeline-syntax.
  2. Select the browserstack:BrowserStack in the Sample Step dropdown menu.
  3. Use the dynamically populated area below the Sample Step dropdown to configure the selected step.
  4. Click Generate Pipeline Script to create a snippet of Pipeline which can be copied and pasted into a Pipeline. Image showing Jenkins Configuration with SnippetGenerator selected on left and BrowserStack selected under Sample Step

Configuring BrowserStack Local

BrowserStack Local Testing allows you to test web applications hosted on private, development, and internal servers. With the Local testing binary, you can create a secure, private connection between the BrowserStack Selenium Grid and your internal servers. The BrowserStack Jenkins plugin is responsible for:

  • Downloading the BrowserStack Local binary for every platform that the build job is running on
  • Setting up and tearing down the secure tunnel.
Note: BrowserStack Local can only be configured per job and not via global configuration.

To enable BrowserStack Local follow these steps

Under the Build Environment section check the box next to BrowserStack Local. BrowserStackLocal checkbox under Build Environment Section

  1. If you are using an externally downloaded binary, you can enter its location at BrowserStack Local Path. If left empty, the plugin will automatically download the binary (recommended). This is recommended especially if you are using Jenkins in master-slave configurations, since the plugin will download the appropriate binary for the build agent OS.
  2. Use BrowserStack Local Options to set any additional configuration options when running the binary (See the full list of local testing options)

To enable BrowserStack Local using a Jenkinsfile add localConfig option as shown in the sample code:

browserstack(credentialsId: '<browserstackCredentialsId>', localConfig: [localOptions: '<local-options>', localPath: '/path/to/local']) {
    // code for executing test cases
Note: Use localOptions to set any additional configuration options when running the binary (See the full list of local testing options)) Once you’ve integrated BrowserStack Local through the Jenkinsfile, you can run your Selenium tests on websites hosted on private, development, and internal servers safely and securely.

Once you’ve integrated BrowserStack Local through the Jenkins plugin, you can run your Selenium tests on websites hosted on private, development, and internal servers safely and securely. Refer to the sample code in the below section.

Using Environment variables

The BrowserStack Jenkins plugin sets the following environment variables:


Use these environment variables to set the capabilities in your tests. For example:

String username = System.getenv("BROWSERSTACK_USERNAME");
String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY");
String buildName = System.getenv("BROWSERSTACK_BUILD_NAME");
String browserstackLocal = System.getenv("BROWSERSTACK_LOCAL");
String browserstackLocalIdentifier = System.getenv("BROWSERSTACK_LOCAL_IDENTIFIER");

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("os", "Windows");
capabilities.setCapability("os_version", "10");
capabilities.setCapability("browser", "chrome");
capabilities.setCapability("browser_version", "latest");
capabilities.setCapability("name", "BStack-[Java] Sample Test"); // test buildName
capabilities.setCapability("build", buildName); // CI/CD job name using BROWSERSTACK_BUILD_NAME env variable
capabilities.setCapability("browserstack.local", browserstackLocal);
capabilities.setCapability("browserstack.localIdentifier", browserstackLocalIdentifier);
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + ""), capabilities);
var username = process.env.BROWSERSTACK_USERNAME;
var accessKey = process.env.BROWSERSTACK_ACCESS_KEY;
var buildName = process.env.BROWSERSTACK_BUILD_NAME;
var browserstackLocal = process.env.BROWSERSTACK_LOCAL;
var browserstackLocalIdentifier = process.env.BROWSERSTACK_LOCAL_IDENTIFIER;

var capabilities = {
	"os" : "Windows",
	"os_version" : "10",
	"browser" : "chrome",
	"browser_version" : "latest",
	"name": "BStack -[Jenkins] Sample Test", // test name
	"build" : buildName, // CI/CD job name using BROWSERSTACK_BUILD_NAME env variable
	"browserstack.local" : browserstackLocal,
	"browserstack.localIdentifier" : browserstackLocalIdentifier,
	"browserstack.user" : username,
	"browserstack.key" : accessKey

var driver = new webdriver.Builder().
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
namespace SeleniumTest {
  class Program {
    static void Main(string[] args) {
      username = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME");
	  accessKey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY");
	  buildName = Environment.GetEnvironmentVariable("BROWSERSTACK_BUILD_NAME");
	  browserstackLocal = Environment.GetEnvironmentVariable("BROWSERSTACK_LOCAL");
	  browserstackLocalIdentifier = Environment.GetEnvironmentVariable("BROWSERSTACK_LOCAL_IDENTIFIER");

      IWebDriver driver;
      OpenQA.Selenium.Chrome.ChromeOptions capability = new OpenQA.Selenium.Chrome.ChromeOptions();
      capability.setCapability("os", "Windows", true);
      capability.AddAdditionalCapability("os_version", "10", true);
      capability.AddAdditionalCapability("browser", "Chrome", true);
      capability.AddAdditionalCapability("browser_version", "latest", true);
      capability.AddAdditionalCapability("name", "BStack-[Jenkins] Sample Test", true); // test name
      capability.AddAdditionalCapability("build", buildName, true); // CI/CD job name using BROWSERSTACK_BUILD_NAME env variable
      capability.AddAdditionalCapability("browserstack.local", browserstackLocal, true);
	  capability.AddAdditionalCapability("browserstack.localIdentifier", browserstackLocalIdentifier, true);
      capability.AddAdditionalCapability("browserstack.user", username, true);
      capability.AddAdditionalCapability("browserstack.key", accessKey, true);
            driver = new RemoteWebDriver(
              new Uri(""), capability

            // test steps
$username = getenv("BROWSERSTACK_USERNAME");
$accessKey = getenv("BROWSERSTACK_ACCESS_KEY");
$buildName = getenv("BROWSERSTACK_BUILD_NAME");
$browserstackLocal = getenv("BROWSERSTACK_LOCAL");
$browserstackLocalIdentifier = getenv("BROWSERSTACK_LOCAL_IDENTIFIER");

$caps = array(
  "os" => "Windows",
  "os_version" => "10",
  "browser" => "chrome",
  "browser_version" => "latest",
  "name" => "BStack-[Jenkins] Sample Test", // test name
  "build" => $buildName, // CI/CD job name using BROWSERSTACK_BUILD_NAME env variable
  "browserstack.local" => $browserstackLocal,
  "browserstack.localIdentifier" => $browserstackLocalIdentifier

$web_driver = RemoteWebDriver::create(
  "https://" . $username . ":" . $accessKey . "",
username = os.getenv("BROWSERSTACK_USERNAME")
access_key = os.getenv("BROWSERSTACK_ACCESS_KEY")
build_name = os.getenv("BROWSERSTACK_BUILD_NAME")
browserstack_local = os.getenv("BROWSERSTACK_LOCAL")
browserstack_local_identifier = os.getenv("BROWSERSTACK_LOCAL_IDENTIFIER")

caps = {
 'os': 'Windows',
 'os_version': '10',
 'browser': 'chrome',
 'browser_version': 'latest',
 'name': 'BStack-[Jenkins] Sample Test', # test name
 'build': build_name, # CI/CD job name using BROWSERSTACK_BUILD_NAME env variable
 'browserstack.local': browserstack_local,
 'browserstack.localIdentifier': browserstack_local_identifier,
 'browserstack.user': username,
 'browserstack.key': access_key

driver = webdriver.Remote(
browserstack_local = ENV["BROWSERSTACK_LOCAL"]
browserstack_local_identifier = ENV["BROWSERSTACK_LOCAL_IDENTIFIER"]

caps =
caps["os"] = "Windows"
caps["os_version"] = "10"
caps["browser"] = "chrome"
caps["browser_version"] = "latest"
caps["name"] = "BStack-[Jenkins] Sample Test" # test name
caps["build"] = build_name # CI/CD job name using BROWSERSTACK_BUILD_NAME env variable
caps["browserstack.local"] = browserstack_local
caps["browserstack.localIdentifier"] = browserstack_local_identifier
caps["browserstack.user"] = username
caps["browserstack.key"] = access_key

driver = Selenium::WebDriver.for(:remote,
  :url => "",
  :desired_capabilities => caps)
my $browserstackLocal = $ENV{"BROWSERSTACK_LOCAL"};
my $browserstackLocalIdentifier = $ENV{"BROWSERSTACK_LOCAL_IDENTIFIER"};

my $caps = {
  "os" => "Windows",
  "os_version" => "10",
  "browser" => "chrome",
  "browser_version" => "latest",
  "name" => "BStack-[Jenkins] Sample Test", # test name
  "build" => $buildName, # CI/CD job name using BROWSERSTACK_BUILD_NAME env variable
  "browserstack.local" => $browserstackLocal,
  "browserstack.localIdentifier" => $browserstackLocalIdentifier

my $host = "$username:$accessKey\";

my $driver = new Selenium::Remote::Driver('remote_server_addr' => $host,
  'port' => '80', 'extra_capabilities' => $caps);
Note: You must pass browserstack.local and browserstack.localIdentifier capabilities to test on your local development servers.

Viewing test report in Jenkins

The BrowserStack Jenkins plugin enables you to embed the test results from BrowserStack Automate into Jenkins. It shows summary of the build, and a grid of all the sessions of that build. The plugin helps you to debug faster by highlighting failed tests and linking tests to the Automate dashboard.

Warning: Please make sure to use BROWSERSTACK_BUILD_NAME environment variable to set build name in your test code. If you don’t use the BROWSERSTACK_BUILD_NAME environment variable, the plugin will not be able to embed reports in Jenkins. Refer Using Environment variables section on how to use environment variables.

Enabling reporting is a simple process and doesn’t require any code change, follow the below steps:

  1. Click on Add post-build action dropdown in Post-build Actions section Jenkins UI click on add post-build action
  2. Select BrowserStack Test Report from the dropdown Browserstack automate jenkins plugin - Add Browserstack Test Report
  3. Click Save

Use the code in your Jenkinsfile

browserStackReportPublisher 'automate'

This is a post build step and should be added after the browserstack block in the Jenkinsfile.

With this integration, you can now view the results of your Selenium Webdriver tests within Jenkins. You can know the summary of a build: Browserstack generated report on Jenkins

You can view the list of session of a build by clicking on View Full BrowserStack Report or by clicking on BrowserStack Test Report link in the sidebar. BrowserStack Test Report

Selecting any session from this table will take you to the Automate dashboard where you can refer to video logs, text logs, screenshots, and other debugging options for a session.

Note: This plugin also supports integration with the reporting framework in Java - TestNG and JUnit & NodeJS - Protractor and WebdriverIO. Read more about integrating with reporting frameworks to know more about the integration steps.


By following the steps outlined in this guide, you should have a seamless integration between your existing automation in Jenkins, your Selenium tests, and the BrowserStack Selenium grid. This will help you leverage all the benefits of test automation along with the scale and coverage offered by BrowserStack.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked

Thank you for your valuable feedback

Is this page helping you?


We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked

Thank you for your valuable feedback!

Talk to an Expert
Talk to an Expert