Skip to main content

Jenkins

Integrate Low Code Automation API with Jenkins to trigger test suites and monitor build statuses efficiently.

To integrate the provided Groovy script into your existing Jenkins pipeline, insert it within a stage. Make sure to replace placeholders with actual BrowserStack credentials.

Make sure the jenkins pipeline-utility-steps plugin is installed.

Use the following code snippet which contains the REST API request to integrate Jenkins pipeline with Low Code Automation:

Groovy
Copy icon Copy
pipeline {
   agent any
  
   stages {
       stage('Trigger Test Suite') {
           steps {
               script {
                   def response = sh(script: "curl -u YOUR_USERNAME:YOUR_ACCESS_KEY -X POST 'https://lcnc-api.browserstack.com/api/v1/test-suite/${TEST_SUITE_ID}/run'", returnStdout: true).trim()
                   def json = readJSON text: response
                   env.BUILD_ID = json.build_id
               }
           }
       }
       stage('Check Build Status') {
           steps {
               script {
                   def buildStatus = ""
                   def retryInterval = 30 // Seconds between retries
                   while (buildStatus != "passed" && buildStatus != "failed") {
                       def response = sh(script: "curl -u YOUR_USERNAME:YOUR_ACCESS_KEY 'https://lcnc-api.browserstack.com/api/v1/builds/${BUILD_ID}/status'", returnStdout: true).trim()
                       def json = readJSON text: response
                       buildStatus = json.build_status
                       if (buildStatus == "passed" || buildStatus == "failed") {
                           break
                       }
                       sleep retryInterval
                   }
                   if (buildStatus == "passed") {
                       echo "Build passed"
                       // Add further steps for actions to be taken if build passed
                   } else if (buildStatus == "failed") {
                       error "Build failed"
                   } else {
                       error "Build status unstable"
                   }
               }
           }
       }
   }
}

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?

Yes
No

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
Download Copy Check Circle