Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Bitbucket is a well-known CI/CD tool available on-premises and as SaaS. In this document we detail the integration with Bitbucket Cloud, namelly namely using Pipelines.

Xray does not provide a specific plugin for Bitbucket; however, it is easy to setup set up Bitbucket in order to integrate it with Xray Cloud.

Since Xray provides a full REST API, you may interact with Xray, for submitting results for example.


Table of Contents

Submitting test automation results to  Xray

JUnit example

In this scenario, we want to get visibility of the automated test results from some tests implemented in Java, using the JUnit framework. 

This recipe could also be applied for other frameworks such as NUnit or Robot (if supported).

We need to setup set up a Git repository containing the code along with the configuration for Bitbucket build process.

...

Code Block
languagejs
title.gitlabbitbucket-cipipelines.yml
# Use Maven 3.5 and JDK8
image: maven:3.5-jdk-8


pipelines:
  default:
    - step:
        caches:
          - maven
        script:
          - |
              echo "building my amazing repo..."
              mvn test
              export token=$(curl -H "Content-Type: application/json" -X POST --data "{ \"client_id\": \"$client_id\",\"client_secret\": \"$client_secret\" }" https://xray.cloud.xpand-it.com/api/v1/authenticate| tr -d '"')
              curl -H "Content-Type: text/xml" -H "Authorization: Bearer $token" --data @target/surefire-reports/TEST-com.xpand.java.CalcTest.xml  "https://xray.cloud.xpand-it.com/api/v1/import/execution/junit?projectKey=CALC"
              echo "done"

...

We're using "curl" utility that comes in Unix based OS'es but you can easily use another tool to make the HTTP request; however, "curl" is provided in the container used by Bitbucket.


Cucumber example

In this scenario, we are managing the specification of Cucumber Scenarios/Scenario Outline(s) based tests in Jira, using Xray, as detailed in the "standard workflow" mentioned in Testing in BDD with Gherkin based frameworks (e.g. Cucumber).

Then we need to extract this specification from Jira (i.e. generate related Cucumber .feature files), and run it in Bitbucket against the code that actually implements each step that are is part of those scenarios.

Finally, we can then submit the results back to JIRA and they'll be reflected on the related entities. 

...

The Bitbucket Pipelines configuration file bitbucket-pipelines.yml contains the definition of the build steps, including extracting the cucumber specification from Xray, running the automated tests, and submitting back the results.

Code Block
languagejs
title.gitlabbitbucket-cipipelines.yml
# This is a sample build configuration for Ruby.
# Check our guides at https://confluence.atlassian.com/x/8r-5Mw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: ruby:2.35

pipelines:
  default:
    - step:
        caches:
          - bundler
        script: # Modify the commands below to build your repository.
          - |
              apt-get update -qq
              apt-get install unzip
              gem install cucumber
              gem install rspec-expectations
              export token=$(curl -H "Content-Type: application/json" -X POST --data "{ \"client_id\": \"$client_id\",\"client_secret\": \"$client_secret\" }" https://xray.cloud.xpand-it.com/api/v1/authenticate| tr -d '"')
              curl -H "Content-Type: application/json" --output features/features.zip -X GET -H "Authorization: Bearer ${token}"  "https://xray-tst.cloud.xpand-addons.com/api/v1/export/cucumber?keys=$cucumber_keys"
              rm -f features/*.feature
              unzip -o features/features.zip -d features/
              cucumber -x -f json -o data.json
              curl -H "Content-Type: application/json" -X POST -H "Authorization: Bearer ${token}" --data @data.json https://xray.cloud.xpand-it.com/api/v1/import/execution/cucumber
              echo "done"

definitions:
  caches:
    bundler: ./vendor

...

In this example, we're using a variable cucumber_keys defined in the Repository variables (within Pipeline configuration section) in Bitbucket. This variable contains one or more keys of the issues that will be used as source data for generating the Cucumber .feature files; it can be the key(s) of Test Plan(s), Test Execution(s), Test(s), requirement(s). For more info, please see: Exporting Cucumber Tests - REST.



Triggering automation/builds from within Xray / Jira

Please have a look at Taking advantage of Jira Cloud built-in automation capabilities to know how to implement this.

Related articles