4 minutes read

POSTED Jan, 2022 dot IN Testing

Integration of Thundra Foresight with Bitbucket Pipelines

Burak Kantarcı

Written by Burak Kantarcı


Product Manager @Thundra

linkedin-share
 X

Foresight is an automated observability tool that helps developers effectively and efficiently monitor and debug their test runs in a CI/CD environment. It also helps them optimize the execution time and performance of their CI builds by providing workflow analytics and metrics.

With full visibility of your test runs and in-depth details on each test, Foresight makes it easy to troubleshoot failed tests, latency issues, and erroneous code—all while providing a faster and more efficient way to solve those issues.

Foresight’s recently released integration with the Bitbucket Pipelines makes adding the Foresight agent to your pipeline seamless. Furthermore, Foresight’s publicly accessible Bitbucket pipe can be configured to add the Foresight agent to your pipeline.

In this article, we’ll go through the step-by-step process of integrating Bitbucket Pipelines with Foresight and demonstrate its advantages.

Prerequisites

Before integrating the Bitbucket Pipelines with Foresight, you must have a Thundra account and create a Foresight project.

Creating a Thundra Account

If you don’t already have one, you’ll need to create a Thundra account. Signing up for Thundra is easy and you can even use the single sign-on feature with your Google or GitHub account:

Figure 1: Create a Thundra account

Thundra offers three products, Foresight, Sidekick, and APM, and you can use all of them with the same Thundra account.

For the purpose of this tutorial, once you sign up, select the Foresight product:

Figure 2: Thundra tools

Creating a Foresight Project

To create a project on Foresight, go to the “Connect Repositories” tab, and click on the “Start now with your project” link.

Figure 3: Foresight demo projects

Next, give a unique name to your project and click on the “Create” button:

 Figure 4: Create a Foresight project

This will create a new Foresight project and you’ll be able to see it under the “Repositories” tab:

Figure 5: Foresight projects

Integrating Foresight with Bitbucket

Foresight leverages the Bitbucket pipes to integrate your Bitbucket Pipelines with the Foresight project. Foresight’s Bitbucket pipe supports both Maven and Gradle development tools. To integrate the Foresight project with your pipeline, you need to edit the bitbucket-pipelines.yml and add the following integration script before your Maven or Gradle build commands:


script:
 - pipe: atlassian/thundra-foresight-maven-initializer:1.0.4
   variables:
     THUNDRA_APIKEY: $THUNDRA_APIKEY
     THUNDRA_AGENT_TEST_PROJECT_ID: $THUNDRA_AGENT_TEST_PROJECT_ID

Foresight’s Bitbucket pipe needs the following two variables to successfully integrate your pipeline with Foresight:

  • THUNDRA_APIKEY: This is the API key of your Foresight account that connects your pipeline with the Thundra Java agent.
  • THUNDRA_AGENT_TEST_PROJECT_ID: This is your Foresight project ID, which connects the project with your pipeline workflows to capture your test runs.

You can obtain these values from the project settings page of your Foresight account:

Figure 6: Foresight project settings

Since these variables contain confidential information, you may want to store them as the repository variables in your Bitbucket Pipelines and reference them in the integration script provided above. Below is a view of where to enter your variables in the repository.

Figure 7: Bitbucket repository variables

Storing the variables this way will help you to keep your account information safe from unauthorized access.

Next, we’ll use a basic example to demonstrate the integration of Maven and Gradle projects with Foresight.

Using Maven

If you are using Maven as your development tool, you’ll need to add the integration script provided above before the Maven verify or install commands in your bitbucket-pipelines.yml file.

You can see the following example demonstrating the integration of the Maven project in a Bitbucket Pipelines with Foresight:


image: maven: 3.6.3

pipelines:
default:
  - step:
      name: Build and Test User Application
      caches:
        - maven
      script:
        - pipe: thundra-io/thundra-foresight-maven-initializer:1.0.6
          variables:
            THUNDRA_APIKEY: $THUNDRA_APIKEY
            THUNDRA_AGENT_TEST_PROJECT_ID: $THUNDRA_AGENT_TEST_PROJECT_ID
            THUNDRA_AGENT_DEBUG_ENABLE: $THUNDRA_AGENT_DEBUG_ENABLE
        - mvn -B verify --file pom.xml

As you can see, we are using the mvn verify command to build and test our Maven project after adding the Foresight integration script. If you add the mvn verify command before the script, you won't see any test runs on your Foresight project.

Using Gradle

If you are using Gradle as your development tool, you’ll need to add the Foresight integration script before the Gradle build or test commands. You’ll also need to add the init script parameter in your Gradle build or test commands.

The following example shows the integration of the Gradle project in a Bitbucket Pipelines with Foresight:


image: gradle: 3.6.3

pipelines:
default:
  - step:
      name: Build and Test User Application
      caches:
        - maven
      script:
        - pipe: thundra-io/thundra-foresight-maven-initializer:1.0.6
          variables:
            THUNDRA_APIKEY: $THUNDRA_APIKEY
            THUNDRA_AGENT_TEST_PROJECT_ID: $THUNDRA_AGENT_TEST_PROJECT_ID
            THUNDRA_AGENT_DEBUG_ENABLE: $THUNDRA_AGENT_DEBUG_ENABLE
        - - gradle build --init-script $BITBUCKET_CLONE_DIR/thundrainit.gradle

You may notice that, other than the gradle build command to build and test the project, this is similar to the Maven script. And as we noted above, this won’t work if you add the Gradle command section before the integration script.

Monitoring Tests on Foresight with Bitbucket Integration

Foresight aggregates all of the information it gathers about your test runs on one platform. You can view both high-level and in-depth details of your test runs and their performance in multiple dashboards.

We’ll walk you through the various dashboards and features of Foresight that let you monitor and debug your test runs more efficiently and effectively. Once your Bitbucket Pipelines is triggered, you can see the real-time status summary of your test run at every commit on the Foresight dashboard:

Figure 8: Application overview dashboard

You can then get a detailed view of any test run by just clicking on it:

Figure 9: Test run overview dashboard

This dashboard provides the high-level details of the test run, such as its execution time; list of test suites; the number of failed, passed, skipped, or aborted test suites; Git environment (like Bitbucket); and the Git branch on which the tests were executed. It also displays some analytics on the tests, such as slowest or most-failed tests.

Similarly, you can view the high-level details of any test run’s test suite just by clicking on the relevant suite:

Figure 10: Test suite overview dashboard

Foresight also provides contextualized information on your tests in the form of logs, metrics, traces, and performance charts:

Figure 11: Test detail view

In this post, we’ve shown a glimpse of the features provided by Foresight. To gain a greater understanding of the tool, go through our documentation to explore Foresight integrations with several open-source applications.

Conclusion

Blocked CI pipelines lead to delayed delivery of software. Thundra Foresight is designed to help developers and testers find the root cause of these blockages and work quickly to resolve them. You can also leverage the distributed tracing and Time-Travel Debugging features of Foresight with their trace maps and trace charts. This gives you full observability into your test execution.

In this article, we’ve seen how easy it is to integrate a Bitbucket Pipeline with the Thundra Foresight tool using Bitbucket pipes. Rather than browsing the logs in the Bitbucket Pipelines, integrating Foresight helps you quickly and easily debug failed tests.

Visit our extended documentation to help you get started with the integration between Thundra Foresight and Bitbucket.

You can contact us anytime for your questions and feedback. Join our community slack, send us a message on our contact us page, or send us a dm on Twitter.

Take your seat in Thundra's thrilling world if you still didn't. It is free for a limited time only!