GitLab
GitLab CI/CD is a software development tool that allows organizations to implement “continuous” methodologies.
In this document, we will show you how to integrate AgileTest with it.
Firstly, you need to acquire Client id and Client secret from AgileTest. Please refer to this document for more details Access API documentation.
Make sure your account has permission to create TestCase and TestExecution issues; otherwise, the import will fail.
Setup with Gitlab
In your Gitlab repository, go to Settings → CI/CD → Variables, and add the variables as follows CLIENT_ID, CLIENT_SECRET, and PROJECT_KEY.
.png?inst-v=e3835335-d0be-4f4c-a82c-c62b3d80caa9)
Variables screen
Ensure you untick the Project Variable option for all created variables. Otherwise, you won't be able to access them in the YAML file.

Edit variable
Upload test result
Here's a JUnit report example for you to experiment with:
If you need more detailed examples, please refer to our public repository on AgileTest GitHub for other sample projects.
Use API
Below is a sample .gitlab-ci.yml file.
stages:
- test
tests:
stage: test
image: mcr.microsoft.com/playwright:v1.42.1-jammy
script:
- npm ci
- npm run test
- 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 'https://api.agiletest.app/ds/test-executions/junit?projectKey=$PROJECT_KEY' -X POST -H 'Content-Type:application/xml' -H 'Authorization:JWT $token' --data @results.xml
- echo "done"
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 Test execution and Test cases accordingly.
To learn more about these endpoints, please refer to this document API document.
Use AgileTest CLI
# You can override the included template(s) by including variable overrides
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
# Note that environment variables can be set in several places
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
stages:
- test
- upload-report
tests:
stage: test
image: mcr.microsoft.com/playwright:v1.42.1-jammy
script:
- npm ci
- npm run test
artifacts:
name: test_result
paths:
- playwright-report/results.xml
upload-report:
stage: upload-report
image:
name: ghcr.io/agiletestapp/agiletest-cli:latest
entrypoint: [""]
script:
- |
agiletest --client-id ${CLIENT_ID} --client-secret ${CLIENT_SECRET} \
test-execution import \
--framework-type junit --project-key ${PROJECT_KEY} \
playwright-report/results.xml
In this .gitlab-ci.yml file, we have 2 jobs named tests and upload-report. Each of them is associated in a different stage and run in a container of different docker image.
In tests job, we run the automation test scripts and the process yields the reports. Then the report is uploaded to Gitlab artifact with the name test_result. By default, all artifacts of jobs belonging to a prior stage are downloaded automatically in the next stage. As a result, in upload-report, we use AgileTest command as below to upload it onto AgileTest.
agiletest --client-id ${CLIENT_ID} --client-secret ${CLIENT_SECRET} \
test-execution import \
--framework-type junit --project-key ${PROJECT_KEY} \
playwright-report/results.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!