Test results upload from Jenkins

Test results upload from Jenkins

Main Jenkins’ upload workflow uses dedicated plug-in or allurectl.

Plugin installation

  1. Download allure-jenkins-x.xx.x.hpi plug-in from dl.qameta.io.
  2. In Jenkins’ main page jump to Manage Jenkins » Manage Plugins.

Jenkins manage plug-ins

  1. Jump to Advanced tab, click Choose File and select the allure-jenkins.hpi you downloaded in the step #1.

    Jenkins upload plug-ins

  2. Click Upload

  3. Jenkins will install the plug-in, and you will be able to proceed to further steps of the integration process.

Authenticate Jenkins’ build jobs

Authentication token

For a user on Allure TestOps side you need to create API token.

This API token will be used by Jenkins to authenticate on Allure TestOps server.

  1. Log in to Allure TestOps with dedicated account you are going to use to upload test results. That could be your profile as well.
  2. Go to user’s profile.

Allure go to profile

  1. In the section API tokens click a green button that says Create.
  2. Name your API token and click Submit. Always give meaningful names to all the configuration parameters.

Allure go to profile

Allure will randomly generate the token and show you in modal window.

  1. Copy the token and save it in a safe place as it cannot be retrieved by Allure TestOps means.

Add your Allure server instance information to Jenkins configuration

  1. Open Jenkins configuration page: Manage Jenkins > Configure System

  2. Navigate to Allure Servers section of the configuration page

Allure Server List

  1. Click Add Allure Server button and setup server location

Allure Server Add

  1. In Credentials section click Add button and create a credential with Kind parameter Kind = Secret text and paste the token you generated on the previous step.

Credentials Add

  1. Choose created credentials from the drop-down list Credentials and press Test Connection button

Allure Server Test

  1. Save Jenkins’ configuration

That’s it. Now, you can configure your build jobs to send test results to Allure TestOps server.

Build jobs

Configure build jobs

The examples below show the following jobs configurations:

  1. Single Freestyle build job configuration.
  2. Single Pipeline build job configuration.

Single Freestyle build job configuration

  1. Open job configuration page

  2. Navigate to Build Environment section

  3. Enabled Allure: upload results and set it up:

Freestyle Job

  • Server is the name of Allure TestOps server you’ve assigned in Configure System of Jenkins.
  • Project is a drop-down list that has all the project from Allure TestOps server. This will set the destination project where your test results will be stored.
  • Launch name - this will appear in Allure TestOps launches area, where all the tests results are stored, analysed and processed. If you use Jenkins’ variables, then launch name will be dynamically changed accordingly to the build number.
  • Launch tags - tags for a particular job, on Allure TestOps side it will help you filtering the tests.
  • Results - path on the CI server, where you store the test results of this very build job.

Single Pipeline build job configuration

pipeline {
    agent any

    stages {
        stage('Checkout') {
            steps {
                git url: 'https://github.com/eroshenkoam/allure-example.git'
            }
        }
        stage('Build') {
            steps {
                withAllureUpload(serverId: 'server.testops.cloud', projectId: '99', results: [[path: 'build/allure-results']]) {
                    sh './gradlew clean test'
                }
            }
        }
    }
}

Using allurectl in Jenkins pipelines

pipeline {
    agent any

    environment {
        ALLURE_ENDPOINT      = 'https://<allure-test-ops>:<port>'
        ALLURE_TOKEN         = 'c1b5daab-ccfd-4dc9-bcc4-6db85165bcac'
        ALLURE_PROJECT_ID    = '2'
        ALLURE_RESULTS       = 'build/allure-results'
    }
    stages {
        stage('Checkout') {
            steps {
                git url: 'https://github.com/eroshenkoam/allure-example.git'
            }
        }
        stage('Build') {
            steps {
                sh 'wget https://github.com/allure-framework/allurectl/releases/download/1.22.1/allurectl_linux_amd64 -O allurectl && chmod +x allurectl'
                sh './allurectl watch -- ./gradlew clean test'
            }
        }
    }
}