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 your GitLab repository
In your Gitlab repository, go to Settings → CI/CD → Variables, and add the variables as follows CLIENT_ID, CLIENT_SECRET, PROJECT_KEY, BASE_AUTH_URL, and BASE_URL.
Variable 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
Variables
Description
Is secured?
Example
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
CLIENT_ID
The client id that you have requested earlier
******
CLIENT_SECRET
The client secret that you have requested earlier
******
PROJECT_KEY
Your project key
RKE
On the other hand, if you are working with AgileTest Data Center version, you only need 3 variables as follows.
Variables
Description
Is secured?
Example
DC_TOKEN
Your Personal access token
BASE_URL
Base URL to submit your report to
PROJECT_KEY
Your project key
RKE
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.
AgileTest Cloud - YAML file
AgileTest Cloud - .gitlab-ci.yml
YAML
stages:
- test
tests:
stage: test
image: mcr.microsoft.com/playwright:v1.42.1-jammy
script:
- npm ci
- npm run test
- export token=$(curl -X POST "$BASE_AUTH_URL/api/apikeys/authenticate" -H 'Content-Type:application/json' --data '{"clientId":"'"$CLIENT_ID"'","clientSecret":"'"$CLIENT_SECRET"'"}' | tr -d '"')
- curl -X POST "$BASE_URL/ds/test-executions/junit?projectKey=$PROJECT_KEY" -H "Content-Type:application/xml" -H "Authorization:JWT $token" --data @"./playwright-report/results.xml"
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/junit 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.
AgileTest Data center - YAML file
For Data center version, we only use 1 endpoint ds/test-executions/nunit with DC_TOKEN variable instead of the token that is requested using client id and client secret. Let’s take a look at the file below!
AgileTest Data center - .gitlab-ci.yml
YAML
stages:
- test
tests:
stage: test
image: mcr.microsoft.com/playwright:v1.42.1-jammy
script:
- npm ci
- npm run test
- curl -X POST "$BASE_URL/ds/test-executions/junit?projectKey=$PROJECT_KEY" -H "Content-Type:application/xml" -H "Authorization:Bearer $DC_TOKEN" --data @"./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.
Same as Cloud, in this file we also have 2 jobs, tests and upload-report. However, in upload-report job, the command would look a little bit different 😉 .
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.
View Pipeline Status
AgileTest provides a simple way to track the status of your pipeline after it has been triggered. To enable this feature, just add the following directives to your workflow file.
For Cloud version, we use the endpoint test-executions/{test_execution_id}/pipeline/history
However, if you are working with AgileTest Data center version, please use rest/agiletest/1.0/test-executions/{test_execution_id}/pipeline/history instead.
Your file should look like this now.
YAML file that includes pipeline status update call
BASH
stages:
- test
tests:
stage: test
image: mcr.microsoft.com/playwright:v1.42.1-jammy
script:
- npm ci
- npm run test
- export token=$(curl -X POST "$BASE_AUTH_URL/api/apikeys/authenticate" -H 'Content-Type:application/json' --data '{"clientId":"'"$CLIENT_ID"'","clientSecret":"'"$CLIENT_SECRET"'"}' | tr -d '"')
- curl -X POST "$BASE_URL/ds/test-executions/junit?projectKey=$PROJECT_KEY" -H "Content-Type:application/xml" -H "Authorization:JWT $token" --data @"./playwright-report/results.xml"
after_script:
- if [ "$CI_JOB_STATUS" == "success" ]; then RESULT="success"; else RESULT="failed"; fi
- export token=$(curl "$BASE_AUTH_URL/api/apikeys/authenticate" -X POST -H 'Content-Type:application/json' --data '{"clientId":"'"$CLIENT_ID"'","clientSecret":"'"$CLIENT_SECRET"'"}' | tr -d '"')
- curl -H "Content-Type:application/json" -H "Authorization:JWT $token" --data '{ "jobURL":"'"$CI_JOB_URL"'", "tool":"gitlab", "result":"'"$RESULT"'" }' "$BASE_AUTH_URL/ds/test-executions/${TEST_EXECUTION_KEY}/pipeline/history?projectKey=${PROJECT_KEY}"
If you include this part to your YAML file, on pipeline’s completion, a history log with pipeline status will be added on the right panel of the execution issue screen as below.
History log on pipeline status
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.