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 with Bitbucket
In your Bitbucket repository, go to Repository settings → Repository 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
.png?inst-v=e3835335-d0be-4f4c-a82c-c62b3d80caa9)
Repository variable screen
Upload test result
Here is a JUnit report example to play around with.
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.
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: 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"
- 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
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 --client-id $CLIENT_ID --client-secret $CLIENT_SECRET \
test-execution import \
--framework-type nunit --project-key $PROJECT_KEY \
$BITBUCKET_CLONE_DIR/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 reports. Then, in upload-report step, the report is uploaded to Agile Test by using AgileTest CLI. Below is the command used for the task.
agiletest --client-id ${CLIENT_ID} --client-secret ${CLIENT_SECRET} \
test-execution import \
--framework-type nunit --project-key ${PROJECT_KEY} \
$BITBUCKET_CLONE_DIR/Nunit/PrimeService.Tests/test-result.xml
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!