How to integrate CAT into GitLab
- An existing project in GitLab
- A repository containing CAT project files along with test definitions
- A basic understanding of CAT
%TESTING_PASSWORD%, with corresponding environment variable values (see details). You can therefore use your project file in pipelines without any additional changes or preprocessing steps, if you define the variable on your machine.
As shown above, the environment variables can be defined in Settings of your project, in section CI/CD. You can modify the variable itself to make it secret or determine the scope:
When you define environment variable
TESTING_PASSWORD, you can use it in your CAT project file as
%TESTING_PASSWORD%. CAT will automatically replace it. You don’t need any preprocessing steps to tweak your project file.
Once your project is set up in GitLab, navigate to the Build icon on the left pane, then click on Pipeline editor, then Configure pipeline as shown in the image below:
This will lead you to this page:
Here you can write your custom code to the pipeline using the editor and commit the changes. If you do not change the settings, it will automatically trigger the pipeline you just created. If the pipeline does not exist, it will create it in the root folder of your current repository.
Below is an example of the code we used to run CAT on a Windows machine with Powershell 7 installed (Powershell 7 is a prerequisite for running CAT).
scriptjob: stage: test image: name: "mcr.microsoft.com/powershell:latest" script: - | pwsh -c ' Write-Host "$env:MadeUpVariable" Install-Module CAT -Force -AcceptLicense Write-Host "CAT installed." $currentDirectory = Get-Location $secondPartOfDirectory = "tests\" $fullPath = Join-Path -Path $currentDirectory -ChildPath $secondPartOfDirectory Import-Module CAT cd $fullPath Invoke-CatProject ' artifacts: when: always paths: - tests.xml reports: junit: tests.xml
This script runs a windows machine hosted by GitLab. The script installs CAT, adjusts the connection string for proper values using secret environment variables and then runs the CAT project which is hosted in the GitLab repo:
The repo also hosts definitions of these tests:
At the end of the script, GitLab expects to receive an artifact which contains the results of tests in XML format, in file
tests.xml. GitLab understands JUnit format. This code (in the root of your project file) will instruct CAT to prepare it for GitLab:
Outputs: - Format: JUnit Path: tests.xml
Don’t forget to change name of your project, change and add other secrets / environment variables if needed etc.
Navigate to the pipeline you want the results for:
Open it and go to tests:
Tests in GitLab cannot be sorted by any category.