Jenkins

How to integrate CAT into Jenkins

Prerequisites

  • Jenkins installed and set up on your machine.
  • An existing CAT project file along with test definitions
  • A basic understanding of CAT

Secrets

To create variables, navigate to this page and click on Add Credentials:

1

There are several options (certificate, token etc.) for a new, global, environment variable:

2

We will use a secret text which contains the connection string to the database on which we want to run the tests:

3

We then reference this variable by its ID (this will be shown in the code below):

4

Pipeline Code

Once your Jenkins is set up, you navigate to the pane on the left and you click New Item:

5

This will lead you to this page:

6

Click on Pipeline and then name it.

There are plenty of options for configuring the pipeline. For our purposes it is enough to just scroll down, choose try sample Pipeline and then click on Pipeline Syntax:

8

This will prompt the Snippet Generator page to appear. Here we can generate the pipeline syntax for various tasks within the pipeline:

9

Let’s fill in the code within the task we chose and then click Generate Pipeline Script. We can then copy the generated code in the pipeline:

10

If you are following this demo step-by-step, generating a pipeline script is not necessary as you will be provided with a sample code below; the code you will be provided with can be input here:

10_1

Below is an example code I used to run CAT on Windows machine with installed Powershell 7 (prerequisite for running CAT).

pipeline {
    agent any

    stages {
        stage('Run CAT') {
            environment {
                ConnectionString = credentials('78597b3e-XXXX-XXXX-XXXX-54e2b72f8007')
            }
            steps {
               pwsh '''

                    Install-Module CAT -Force -AcceptLicense

                    Import-Module CAT

                    Invoke-CatProject
                    '''
            }
        post {
        always {
         junit(testResults: '**\*.xml', allowEmptyResults : true)
        }
            }
        }
    }
}

This script installs CAT, invokes it, runs the tests and then publishes the results of the tests to the pipeline using JUnit. A global secret variable is used to connect to the database on which the tests are run (creation of global secret variable was shown in section 1.)

11

Note the directory workspace and within that is your item (in our case the pipeline is named “testing”, hence the folder “testing”). If neither of these folders exist, you may create them. Then copy the CAT project and test definitions to the directory (in this case, “testing”).

Results

Navigate to the pipeline you want the results for:

12

13

Open it and go to tests:

14

Tests in Jenkins are sorted by categories and the failed tests are highlighted:

15