Skip to main content
Skip table of contents

Jenkins

Jenkins is a popular open-source automation server that helps with Continuous Integration and Continuous Delivery (CI/CD) processes. It allows developers to automate the building, testing, and deployment of software applications.

In this document, you will learn about how to integrate AgileTest with Jenkins.

Firstly, you need to acquire Client id and Client secret from AgileTest. Please refer to this document for more details Access API documentation.

Make sure your account has permission to create TestCase and TestExecution issues; otherwise, the import will fail.

Setup with Jenkins

While this page covers the basics of integrating AgileTest with Jenkins, it will not cover the fundamentals of Docker, which you can refer to in the Docker Getting Started Guide and install Docker on your local machine before proceeding further.

In Jenkins, go to Dashboard Manage JenkinsSystemGlobal properties and tick Environment variables. Then, create 2 variables CLIENT_ID and CLIENT_SECRET and fill in your Client id and Client secret respectively.

Screen Shot 2025-01-13 at 16.26.07.png

Global properties

Upload test result

Here is a JUnit report example to experiment with.

JUnit report example
XML
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite tests="15" failures="0" name="ut.com.xpandit.raven.service.impl.IssueDataSetTest" time="0.163" errors="0" skipped="0">
  <properties>
    ...
  </properties>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidLimitOverflowOption_returnsExpectedSubset" time="0.114"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withNullOptionsAndValidIssue_throwsIllegalArgumentException" time="0.002"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidEmptyOptions_returnsAllIssues" time="0.002"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidGlobalSearchOptions_returnsExpectedTests" time="0.016"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndInvalidColumnSearchOption_returnsAllTests" time="0.007"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidLimitUnderOption_returnsExpectedSubset" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidGlobalSearchOptionThatMachesIssueKey_returnsExpectedTestWithMatchedKey" time="0.006"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidSummaryColumnAscSortOption_returnsExpectedIssuesInAscOrder" time="0.006"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidSummaryColumnDescSortOption_returnsExpectedIssuesInDescOrder" time="0.002"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidGlobalSearchOptionThatMatchesAllElements_returnsAllTests" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidColumnSearchOptionThatMatchesOneElement_returnsOneTest" time="0.002"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidColumnSearchOptionThatMatchesNoIssue_returnsEmptyList" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidGlobalSearchOptionThatMachesNoIssue_returnsEmptyList" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidKeyColumnDescSortOption_returnsExpectedIssuesInDescOrder" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidKeyColumnAscSortOption_returnsExpectedIssuesInAscOrder" time="0.001"/>
</testsuite>

If you need more detailed examples, please refer to our public repository on AgileTest GitHub for other sample projects.

Use API

Next, go back to Dashboard and create a new item of scripted pipeline type.

Screen Shot 2025-01-13 at 16.27.27.png

Then link this pipeline to your project repository.

Below is an example of .jenkinsfile. In it, we add another variable named PROJECT_KEY and assign it with Jira project key, for example “ATP”.

GROOVY
pipeline {
    agent {
        docker {image 'maven:3.9.9-amazoncorretto-17-al2023'}
    }

    environment{
        PROJECT_KEY = 'ATP'
    }

    stages {
        stage('Run test') {
            steps {
                script{
                    sh'echo "Testing.."'
                    sh'mvn test'
                    token=sh(script: """curl 'https://agiletest.atlas.devsamurai.com/api/apikeys/authenticate' -X POST -H 'Content-Type:application/json' --data '{"clientId":"'"${env.CLIENT_ID}"'","clientSecret":"'"${env.CLIENT_SECRET}"'"}'""", returnStdout:true).trim()
                    echo "${token}"
                    sh"""curl "https://api.agiletest.app/ds/test-executions/junit?projectKey=${PROJECT_KEY}" -X POST -H 'Content-Type:application/xml' -H "Authorization:JWT ${token}" --data "@target/surefire-reports/TEST-calculateTest.xml" """
                }
            }
        }
    }
}

In this file, we use 2 endpoints

  • api/v1/apikeys/authenticate to get temporary token using acquired client_id and client_secret.

  • ds/test-executions/nunit to submit test report to Agile Test so that the application could create or update Test execution and Test cases accordingly.

To learn more about these endpoints, please refer to this document API documentation.

Use AgileTest CLI

Agile Test also offers you a simpler way to upload your test result via CLI.

You could find the specs of our CLI here: https://agiletestapp.github.io/agiletest-cli/ .

Below is a sample .jenkinsfile

YAML
pipeline {
    agent none
    environment{
        PROJECT_KEY = 'ATP'
    }
    stages {
        stage('Run test') {
            agent {
                docker {
                    image 'maven:3.9.9-amazoncorretto-17-al2023'
                }
            }
            steps {
                script {
                    sh'echo "Testing.."'
                    sh'mvn test'
                    }
                stash includes: '**/target/surefire-reports/*.xml', name: 'reports'
            }
        }
        stage('Upload report') {
            agent {
                docker {
                    image 'ghcr.io/agiletestapp/agiletest-cli:latest'
                    args '--entrypoint=""'
                }
            }
            steps {
                echo "test"
                sh 'ls'
                script {
                    sh'''agiletest --client-id ${CLIENT_ID} --client-secret ${CLIENT_SECRET} \
                        test-execution import \
                        --framework-type junit --project-key ${PROJECT_KEY} \
                        target/surefire-reports/TEST-calculateTest.xml'''
                }
            }
        }
    }
}

This file sets up two stages: Run Test and Upload Report. Each stage runs in a separate container using a different image. The Run Test stage uses a Maven image to execute the tests, while the Upload Report stage uses a Docker image designed specifically for the Agile Test CLI to upload the test results.

In Run test stage, we run the automation test scripts and the process yields the reports. Then, in Upload report stage, the report is uploaded to Agile Test by using AgileTest CLI. Below is the command used for the task.

BASH
agiletest --client-id ${CLIENT_ID} --client-secret ${CLIENT_SECRET} \
              test-execution import \
              --framework-type junit --project-key ${PROJECT_KEY} \
              target/surefire-reports/TEST-calculateTest.xml

For each test run, a new Test Execution will be created along with linked Test Cases. However, if the Test Cases already exist in your project, Agile Test will only generate a new Test Execution and link the matching Test Cases to it, including the test results.


Should you need any assistance or further AgileTest inquiries, contact here!

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.