Responsive

Unleashing the Power of CI/CD Testing with Bitbucket and Testkube

Unleashing the Power of CI/CD Testing with Bitbucket and Testkube

Last updated
January 14, 2025
Bruno Lopes
Product Leader
Testkube
Share on X
Share on LinkedIn
Share on Reddit
Share on HackerNews
Copy URL

Table of Contents

Start Using Testkube with a Free Trial Today

Subscribe to our monthly newsletter to stay up to date with all-things Testkube.

Last updated
January 14, 2025
Bruno Lopes
Product Leader
Testkube
Share on X
Share on LinkedIn
Share on Reddit
Share on HackerNews
Copy URL

Table of Contents

Various CI/CD tools can facilitate continuous deployment, and Bitbucket is one of them. Combined with Testkube, it offers the ideal way to automate and improve your testing processes.

In this blog post, we'll take a look at how to use Bitbucket Pipelines and Testkube to continuously deploy test cases in the Kubernetes cluster environments as part of the CI/CD pipeline.

What is Bitbucket?

Bitbucket is a code hosting and collaboration tool based on Git that assists development teams in efficiently building, testing, and deploying software. It includes powerful features such as Bitbucket Pipelines, an integrated CI/CD service allowing automated builds, testing, and deployments from within your repositories. Bitbucket simplifies the development lifecycle with its robust integration capabilities and seamless workflow management, making it an ideal choice for teams implementing DevOps practices.

By integrating Bitbucket Pipelines and Testkube, you can utilize test automation and make sure that every change to the code is tested before it goes live, making things faster and more reliable.

Benefits of Using Testkube with CI/CD Pipelines 

The integration of Bitbucket Pipelines and Testkube offers several benefits. Below are listed a few benefits:

  • Automated Testing: Run the tests automatically on every push, lowering the risk of any error.
  • Seamless Integration: Improve the CI/CD workflow by seamlessly integrating the Testkube and Bitbucket pipelines.
  • Improved Code Quality: This integration makes it feasible to identify bugs beforehand, which substantially enhances the quality of the code.
  • Enhanced Security: Testkube ensures that your tests run securely by preventing unnecessary exposure in the CI/CD pipeline, which improves overall system security.

Read more about the benefits of using a tool like Testkube to run your tests from your CI/CD pipeline in the Stop Running Tests with your CI/CD article.

Let’s now understand how to integrate Bitbucket Pipelines with Testkube for a reliable and smooth testing process.

Integrating Bitbucket Pipelines with Testkube

Testkube's integration with any CI/CD tool aims to make the testing process more seamless and efficient. Below is a high-level overview of the actions that we’ll perform:

  • Create a repo with a test workflow file. In this case, we’ll use the k6 test workflow.
  • Configure a pipeline with this repo and trigger it when any new pull request is created.
  • Add our Testkube target cluster’s configuration values in this pipeline.
  • The pipeline then deploys the k6 test to our configured Kubernetes cluster and executes it. 

Prerequisites

Once the prerequisites are met, you should be able to launch a target Kubernetes cluster with a Testkube agent setup and configure a Bitbucket pipeline to deploy and run a k6 test workflow on the target cluster.

To create the API token, refer to our API Token document. To find the Org ID and environment IDs, log in to your Testkube Dashboard and select Settings from the menu bar.

In addition, these IDs and tokens must be stored as variables in Bitbucket to ensure their safe access and use during pipeline execution. For more information, refer to the documentation on Bitbucket variables and secrets

Creating a Test Workflow in Testkube

Testkube Test Workflows are an easy and quick way to define and run tests within a Kubernetes cluster. These YAML-based specifications enable the test to be defined in a single file containing the test, images, artifacts, and resource parameters.

It allows you to create multi-step test workflows that thoroughly manage end-to-end requirements while offering you more freedom and control over the tests.

Discover and learn more about Test Workflows, which enable you to perform efficient and seamless testing in Kubernetes frameworks.

The first step is to create a test workflow. Here's how you can create a test workflow using an example:

  • Login to your Testkube dashboard and navigate to the Test Workflow section.
  • Click the "Add New Test Workflow" button. 
  • A "Create a Test Workflow" dialog box appears, and you can build the sample workflow by selecting the "Start from an Example" option.

Here's a sample Test Workflow I created for k6:

kind: TestWorkflow
apiVersion: testworkflows.testkube.io/v1
metadata:
  name: basic-k6-workflow
  namespace: testkube
  labels:
    docs: example
spec:
	content:
  	files:
    - path: /data/example.js
    content: |-
    	import http from 'k6/http';
      import { sleep } from 'k6';
      export default function () {
      http.get('https://test.k6.io');
      sleep(1);
      };   
   steps:
   - name: Run Tests
   workingDir: /data
   run:
   	image: grafana/k6:0.49.0
    env:
    - name: K6_WEB_DASHBOARD
    	value: "true"
    - name: K6_WEB_DASHBOARD_EXPORT
    	value: k6-test-report.html
    args:
    - run
    - example.js
      artifacts:
      	paths:
      	- k6-test-report.html
        status: {}

We’ll save this k6 test workflow configuration as a YAML file in our Bitbucket repository and configure a Bitbucket pipeline.

Configuring Bitbucket Pipelines

Log in to your Bitbucket account and create a repository containing the test workflow file.

Once your repo has been created, go to Repository Settings and enable Pipelines. It will generate a sample `bitbucket-pipelines.yml` file with some basic configuration. 

We’ll go ahead and configure the pipeline to trigger whenever a new PR is created. 

The file should contain the pipeline configuration, which includes the image to be used, the build steps, and any necessary environment variables or custom configurations.
Let’s look at a bitbucket-pipelines.yml file.

image: kubeshop/testkube-cli

pipelines:
	pull-requests:
    '**':
    	- step:
    		name: Testkube Test
            script:
            	- echo $TESTKUBE_API_TOKEN
            	- testkube set context --api-key                
$TESTKUBE_API_TOKEN --org $TESTKUBE_ORG_ID --env $TESTKUBE_ENV_ID

		# Verify Testkube CLI Installation
        - testkube version
        
        # Run Testkube command to Validate the Connection
        - testkube create testworkflow --name testworkflow-actions -f k6-test-workflow.yaml --update
        - testkube run tw testworkflow-actions

The workflow described above performs the following actions:

  • Sets up a job to connect to the Testkube cloud using the Testkube API key, organization, and environment ID.
  • Creates and runs the k6 test workflow named testworkflow-actions.
  • testkube version: Checks whether the Testkube CLI is properly installed.
  • Runs the test workflow

Note: The --update flag in the run test workflow command ensures that the test workflow is updated with the latest changes and execution history is preserved

Triggering Testkube Test

Make changes to the bitbucket-pipelines.yml file in the repository, and commit the changes by raising a pull request to trigger the pipeline.

Once the pipeline is triggered, Bitbucket Pipelines will execute the test steps specified in the configuration file.

On the Bitbucket interface, click the Pipelines option to view your pipeline's status, detailed information about the log generated during its execution, and other relevant information.

Based on the configuration, we can see that the pipeline triggers with every new PR; it connects to our target Kubernetes cluster, deploys the k6 test from the repo, and executes the test. 

Monitoring the Test Workflow

You can monitor the workflow’s progress and report in the Testkube dashboard or using the Testkube CLI. Let's see how to check the status of the Test Workflow using the dashboard.

  1. Navigate to the Test Workflows tab, where you will see the k6 test workflow named testworkflow-actions that was deployed using the pipeline.
  1. To know more about the status of the test workflow, click on a step.

After the execution, Testkube collects all artifacts, including a stats report with all outputs and results.

The above example demonstrates how simple configuring Testkube with Bitbucket Pipelines is. One can execute advanced scenarios by modifying the workflow and configuring repositories according to their specific requirements.

Summary

We have learned how to set up the Testkube testing workflow with Bitbucket pipelines and how it enhances our testing experience. By integrating the automation capabilities of Bitbucket Pipelines with the testing capabilities of Testkube, you have not only automated the testing process but also created a robust testing framework for the development pipeline. Additionally, this integration not only allows a seamless and efficient testing process but also ensures consistency and reliability in the CI/CD workflows.

So, what are you waiting for? Go one step further and use the collective power of these two to scale your testing processes and deliver reliable releases more quickly. 

Reach out to me to discover how Testkube can transform your testing strategy. You can also join our Slack community to start a conversation or read Testkube documentation to see how Testkube can enhance your GitOps testing workflow, ensuring seamless, efficient, and automated testing within the Kubernetes environments. The future of software testing is here. Are you ready to be a part of it?

In today's fast-paced world of software development, every build and new feature must be thoroughly tested to ensure a seamless experience and an efficient delivery. Continuous testing enables teams to automate test execution at all stages, detecting issues early and confidently delivering reliable updates. Integrating testing with your CI/CD tools ensures that every code submission triggers the necessary tests, accelerating development while allowing you to focus on other vital tasks.

About Testkube

Testkube is a test execution and orchestration framework for Kubernetes that works with any CI/CD system and testing tool you need, empowering teams to deliver on the promise of agile, efficient, and comprehensive testing programs by leveraging all the capabilities of K8s to eliminate CI/CD bottlenecks, perfecting your testing workflow. Get started with Testkube's free trial today.