Integrate AgileTest with GitLab CI/CD pipeline
Integrating AgileTest with GitLab CI/CD pipeline is quite simple, and you can even trigger it directly from AgileTest! Don't know it yet? Let's find out!
Before that, let's understand what GitLab is.
GitLab offers an all-in-one CI/CD platform that enables automated testing, building, and deployment as part of the development lifecycle. With GitLab CI/CD, developers can define pipelines directly within their repositories using a simple .gitlab-ci.yml file, enhancing workflows and supporting continuous integration and delivery from a single DevOps toolchain.
You can watch the video below for a step-by-step guide to integrate AgileTest with GitLab:
Step 1: Setup pipeline variable
In your Gitlab repository, you can go to Settings, then choose CI/CD → Variables. After that, you can add the variables as follows CLIENT_ID, CLIENT_SECRET, PROJECT_KEY, BASE_AUTH_URL, and BASE_URL.
There is one important note here: Make sure that you have the permission to create issues in your project to avoid failure.
Step 2: Run pipeline using API
Next you can upload your test results. There are 2 ways to do that. The first one is using API.
Here is a sample for gitlab yml file:
stages:
- test
tests:
stage: test
image: http://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"
Then, you can go to the pipeline in the GitLab repository and run the latest pipeline.
Step 3: Run pipeline using CLI
The second method to use AgileTest CLI to run the pipeline.
Recommended by LinkedIn
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, you can 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 --base-auth-url $BASE_AUTH_URL --base-url $BASE_URL \
--client-id $CLIENT_ID --client-secret $CLIENT_SECRET \
test-execution import \
--framework-type junit --project-key $PROJECT_KEY \
playwright-report/results.xml
Step 4: Trigger pipeline directly from AgileTest
You can also trigger the pipeline from Agile Test.
To access this feature, you can go to the AgileTest settings in your project by choosing Settings → Automated Test.
Here, you should see most common CI/CD tools, Bitbucket, GitHub, GitLab, and Jenkins. By default, these settings would be disabled.
After enabling one of these platform, a New configuration button will appear for you to create new triggers.
Firstly, you can click New GitLab Configuration button to reveal the configuration dialog.
User is required to fill in details as follows:
And that’s it. By following these steps, you can easily integrate AgileTest with your GitLab CI/CD pipeline to enhance your testing process. If you want to find out more the details, please take a look at our documents: https://docs.devsamurai.com/agiletest/gitlab.