Skip to main content

Integration with Jenkins

In this article, you will learn how to seamlessly integrate Jenkins into your development workflow.

Step 1: Install “Webhook Step” Jenkins plugin

  1. Go to “Manage Jenkins” -> “Manage Plugins”.
  2. Make sure that the necessary Jenkins plugin is installed:
  • Switch to the “Installed” tab and search for the “Webhook Step” plugin.
  • If no results of the search:
    • Switch to the “Available” tab.
    • Search for “Webhook Step”.
    • Install the plugin with “Download now and install after restart”.

Step 2: Define webhook configuration to the Jenkins job/pipeline before tests execution:

def hook = registerWebhook();
def encodedUrl = sh(script: "echo -n ${hook.getURL().toString()} | base64 -w 0", returnStdout: true)

encodedUrl – this is a unique string that will be generated from the Jenkins job/pipeline and connect each reported launch with the appropriate Jenkins run from which the launch was reported.

Step 3: Run test with webhook

Put the encodedUrl variable into the test execution string at the enumeration of RP.attributes. For example (Maven build):

Drp.attributes='k1:v1;k2:v2;rp.webhook.key:${encodedUrl}'

As result launch with attribute rp.webhook.key:${encodedUrl} will be reported. On quality gate finish RP will send request to { encodedUrl } with quality gate results:

{
"launchId": "{launch_id}",
"status": "[PASSED|FAILED|UNDEFINED]"
}

Response can be parsed on the next step.

Step 4: Configure webhook waiting data from RP

a. Option #1

This option allows sending the Quality Gates result status to the separate pipeline stage. It doesn’t affect the tests execution stage, and the status of that stage will be determined by the result of the Quality Gate status. Add additional pipeline stage. Wait for webhook and define the particular TIMEOUT_TIME, how long Jenkins should wait for data from RP:

stage('Wait for webhook') {
timeout(time: params.TIMEOUT_TIME, unit: params.TIMEOUT_UNIT) {

echo 'Waiting for RP processing...'
data = waitForWebhook hook;
echo "Processing finished... ${data}"

def jsonData = readJSON text: data
assert jsonData['status'] == 'PASSED'
}
}

Parameters for TIMEOUT_TIME and TIMEOUT_UNIT can be defined like that:

parameters {
string(name: 'TIMEOUT_TIME', defaultValue: '30', description: '')
string(name: 'TIMEOUT_UNIT', defaultValue: 'SECONDS', description: '')
}

b. Option #2

This option should send the results from the RP to the tests run pipeline stage, and the status of that stage (tests execution) will be determined by the result of the Quality Gate status. Add next code in the pipeline stage, where tests run:

echo 'Waiting for RP processing...'
data = waitForWebhook hook;
echo "Processing finished... ${data}"

def jsonData = readJSON text: data
assert jsonData['status'] == 'PASSED'

If the Jenkins received a response about Quality Gate status from RP, the build status should be appropriately marked:

Jenkins Job StatusQuality Gate StatusDescription
SUCCESSPASSEDQuality Gate is passed
ABORTEDUNDEFINEDThe Jenkins timeout has been exceeded
FAILEDFAILEDQuality Gate is failed