Skip to content

Instantly share code, notes, and snippets.

@idoshamun
Created August 22, 2017 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idoshamun/cfd745d3370f1bddf6b6a41c25d55527 to your computer and use it in GitHub Desktop.
Save idoshamun/cfd745d3370f1bddf6b6a41c25d55527 to your computer and use it in GitHub Desktop.
BrowserStack integration with Jenkins
#!/usr/bin/env groovy
def call(body) {
lock(label: 'BrowserStack', quantity: 1) {
env.BROWSERSTACK_LOCAL_IDENTIFIER = env.BUILD_TAG
// Start the connection
sh "BUILD_ID=dontKillMe nohup /opt/BrowserStackLocal --force-local --only-automate --key ${env.BROWSERSTACK_ACCESSKEY} --local-identifier ${env.BROWSERSTACK_LOCAL_IDENTIFIER} > /var/tmp/browserstack.log 2>&1 & echo \$! > /var/tmp/browserstack.pid"
try {
body()
}
finally {
// Stop the connection
sh "kill `cat /var/tmp/browserstack.pid`"
}
}
}
@idoshamun
Copy link
Author

This is a snippet from our Jenkins shared library which is currently closed source.
It assumes that BrowserStackLocal is installed in /opt directory and that the BrowserStack access key is available via environment variable BROWSERSTACK_ACCESSKEY.
In addition, in order to limit the parallel jobs that can use BrowserStack due to billing issue I use Lockable Resources Plugin.

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