GitLab CI/CD is a software development tool that allows organizations to implement “continuous” methodologies.
🔒
Prerequisite:
Make sure your account has permission to create TestCase and TestExecution issues; otherwise, the import will fail.
As a Jira admin, you can update this permission in the Space setting → Permission → Create Issues.
For the Cloud version, Client id and Client secret are needed. Please refer to this instruction to get them: API integration
For Data Center version, you will need a Personal access token (PAT) instead. In Jira, select ⚙️ (top right corner) → System -> Administeringpersonalaccess tokens, and create yourself a token. Please refer to this article from Jira for more details.
Learn more about how to integrate AgileTest into the GitLab CI/CD pipeline.
1. Setup your GitLab repository
When you integrate AgileTest with GitLab, you need to securely store certain authentication details, such as your Client ID and Client Secret. By doing it, you ensure that sensitive data is kept secure and is not exposed in your code or logs, reuse variables in different places, etc. These credentials are also required for AgileTest to authenticate and communicate with GitLab in the pipeline.
1.1 For Cloud version
We recommend that you set up 5 repository variables:
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 in the API document
POSTapi/v1/apikeys/authenticate to get a temporary token using the acquired client_id and client_secret.
POSTds/test-executions/junit to submit the test report to Agile Test so that the application can create or update Test execution and Test cases accordingly.
2.1.2 For Data Center version
AgileTest Data center - gitlab-pipelines.yml
CODE
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"
For the Data center version, we only use 1 endpoint POSTds/test-executions/nunit with DC_TOKEN variable instead of the token that is requested using the Client Id and Client Secret.
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 supports you in tracking the status of your pipeline after it has been triggered. To enable this feature, just add the following directives to your workflow file.
For the Cloud version, we use the endpoint testexecutions/{test_execution_id}/pipeline/history
For the Data center version, please use rest/agiletest/1.0/test-executions/{test_execution_id}/pipeline/history
Your file should look like this now.
YAML file that includes pipeline status update call
CODE
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}"
Once you include this part in 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.
Should you need any assistance or further AgileTest inquiries, contact our 24/7 Support Desk!
JavaScript errors detected
Please note, these errors can depend on your browser setup.
If this problem persists, please contact our support.