Skip to main content
Skip table of contents

Bitbucket

Bitbucket is one of the widely known CI/CD tool. In this document, we will show you how to integrate AgileTest with Bitbucket via REST API.

However, in order to utilize AgileTest API, Client id and Client secret are needed. Please refer to this instruction to get them first Access API documentation.

Make sure your account has permission to create TestCase and TestExecution issues; otherwise, the import will fail.

Setup your Bitbucket repository

In your Bitbucket repository, go to Repository settingsRepository variables and create respective repository variables for acquired client id and client secret.

In this example, we will create 3 repository variables CLIENT_ID, CLIENT_SECRET, and PROJECT_KEY.

Screenshot 2025-05-15 at 10.54.08-20250515-035431.png

Repository variables

Upload test result

Here is a sample NUnit report to play around with.

JUnit report example
XML
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite tests="15" failures="0" name="ut.com.xpandit.raven.service.impl.IssueDataSetTest" time="0.163" errors="0" skipped="0">
  <properties>
    ...
  </properties>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidLimitOverflowOption_returnsExpectedSubset" time="0.114"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withNullOptionsAndValidIssue_throwsIllegalArgumentException" time="0.002"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidEmptyOptions_returnsAllIssues" time="0.002"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidGlobalSearchOptions_returnsExpectedTests" time="0.016"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndInvalidColumnSearchOption_returnsAllTests" time="0.007"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidLimitUnderOption_returnsExpectedSubset" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidGlobalSearchOptionThatMachesIssueKey_returnsExpectedTestWithMatchedKey" time="0.006"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidSummaryColumnAscSortOption_returnsExpectedIssuesInAscOrder" time="0.006"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidSummaryColumnDescSortOption_returnsExpectedIssuesInDescOrder" time="0.002"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidGlobalSearchOptionThatMatchesAllElements_returnsAllTests" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidColumnSearchOptionThatMatchesOneElement_returnsOneTest" time="0.002"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidColumnSearchOptionThatMatchesNoIssue_returnsEmptyList" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidGlobalSearchOptionThatMachesNoIssue_returnsEmptyList" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidKeyColumnDescSortOption_returnsExpectedIssuesInDescOrder" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidKeyColumnAscSortOption_returnsExpectedIssuesInAscOrder" time="0.001"/>
</testsuite>

If you need more detailed examples, please refer to our public repository on AgileTest GitHub for additional sample projects.

Use API

Below is a sample bitbucket-pipelines.yml file.

YAML
image: mcr.microsoft.com/dotnet/sdk
options:
  docker: true

definitions:
  steps:
    - step: &linting
        name: Linting
        caches:
          - dotnetcore
        script:
          - echo "linting"

pipelines:
  pull-requests:
    develop:
      - step: *linting
    master:
      - step: *linting

  # TODO: build docker image
  branches:
    nunit:
      # - step: *linting
      - step: &run-test
          name: Test and upload report
          script:
            # Run test
            - cd ./Nunit/PrimeService && dotnet restore
            - cd .. && dotnet sln add PrimeService/PrimeService.csproj
            - cd ./PrimeService.Tests && dotnet restore
            - cd .. && dotnet sln add PrimeService.Tests/PrimeService.Tests.csproj
            - dotnet test --logger:"nunit;LogFilePath=test-result.xml"
            # Upload the report
            - export token=$(curl 'https://agiletest.atlas.devsamurai.com/api/apikeys/authenticate' -X POST -H 'Content-Type:application/json' --data '{"clientId":"'"$CLIENT_ID"'","clientSecret":"'"$CLIENT_SECRET"'"}' | tr -d '"')
            - echo $token
            - curl -X POST -H "Content-Type:application/xml" -H "Authorization:JWT $token" --data-binary "@PrimeService.Tests/test-result.xml" "https://api.agiletest.app/ds/test-executions/nunit?projectKey=$PROJECT_KEY"

In this file, we use 2 endpoints

  • api/v1/apikeys/authenticate to get temporary token using acquired client_id and client_secret.

  • ds/test-executions/nunit to submit test report to Agile Test so that the application could create or update Test execution and Test cases accordingly.

To learn more about these endpoints, please refer to this document API document.

Use AgileTest CLI

YAML
image: mcr.microsoft.com/dotnet/sdk
options:
  docker: true

definitions:
  steps:
    - step: &linting
        name: Linting
        caches:
          - dotnetcore
        script:
          - echo "linting"

pipelines:
  pull-requests:
    develop:
      - step: *linting
    master:
      - step: *linting

  branches:
    nunit:
      - step: &run-test
          name: Run test
          script:
            - cd ./Nunit/PrimeService && dotnet restore
            - cd .. && dotnet sln add PrimeService/PrimeService.csproj
            - cd ./PrimeService.Tests && dotnet restore
            - cd .. && dotnet sln add PrimeService.Tests/PrimeService.Tests.csproj
            - dotnet test --logger:"nunit;LogFilePath=test-result.xml"
          artifacts:
            - Nunit/PrimeService.Tests/*.xml
      - step: &upload-report
          name: Upload report to AgileTest using cli
          image: ghcr.io/agiletestapp/agiletest-cli:latest
          script:
            - |
              agiletest \
              --base-auth-url $BASE_AUTH_URL \
              --base-url $BASE_URL \
              --client-id $CLIENT_ID \
              --client-secret $CLIENT_SECRET \
              test-execution import --framework-type nunit \
              --project-key $PROJECT_KEY Nunit/PrimeService.Tests/test-result.xml

In this file, we configure 2 steps, run-test and upload-report. Each step runs in a container of different image. For run-test, we use dotnet image, but in upload-report, the docker image is actually the one built for Agile Test CLI.

In run-test step, we run the automation test scripts and the process yields the report. The report is then pushed to pipeline artifact in order to be used for the later step. Next, in upload-report step, the report is uploaded to AgileTest by using AgileTest CLI. Below is the command used for the task.

BASH
 agiletest --base-auth-url $BASE_AUTH_URL \
            --base-url $BASE_URL \
            --client-id $CLIENT_ID \
            --client-secret $CLIENT_SECRET \
            test-execution import --framework-type nunit \
            --project-key $PROJECT_KEY Nunit/PrimeService.Tests/test-result.xml

As you can see, there are 2 additional variables, BASE_AUTH_URL and BASE_URL, which we will add to our pipeline variable collection.

Variables

Description

Value

BASE_AUTH_URL

Base URL used for requesting authenticating token

https://agiletest.atlas.devsamurai.com

BASE_URL

Base URL to submit your report to

https://api.agiletest.app

Screenshot 2025-05-15 at 10.54.42-20250515-035451.png

Additional pipeline variables

For each test run, a new Test Execution will be created along with linked Test Cases. However, if the Test Cases already exist in your project, Agile Test will only generate a new Test Execution and link the matching Test Cases to it, including the test results


Should you need any assistance or further AgileTest inquiries, contact here!

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.