GitLab

How to integrate CAT into GitLab

Prerequisites

  • An existing project in GitLab
  • A repository containing CAT project files along with test definitions
  • A basic understanding of CAT

Secrets

1

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:

2

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.

Pipeline Code

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:

4

This will lead you to this page:

5

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:

6

The repo also hosts definitions of these tests:

7

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

Note:

Don’t forget to change name of your project, change and add other secrets / environment variables if needed etc.

Results

Navigate to the pipeline you want the results for:

9

Open it and go to tests:

10

Tests in GitLab cannot be sorted by any category.