Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info
titleRequirements

The Jenkins baseline for this app is v2.60.3 and it may not work properly with previous versions. 

...


Manual Installation


Info
titleDownload the latest version of the Jenkins Plugin

You may download the latest version of the Jenkins plugin from the latest Release Notes.


If you have the actual xray-connector.hpi file,

  1. Go to the Update Center of Jenkins in Manage Jenkins > Manage Plugins.
  2. Select the advanced tab
  3. In the Upload Plugin section, click upload and select the file xray-connector.hpi file.


Jenkins Native Installation (via web UI)

Since version 2.1.0, you can install the plugin by using the Jenkins native Web UI. You can read more about how to to it here.

Configuration

Xray for Jenkins is configured in the global settings configuration page  Manage Jenkins > Configure System > Xray for Jira configuration.

Jira servers

The Jira servers configuration defines connections with Jira instances. 

To add a new Jira instance connection, you need to specify some properties:

  1. Configuration alias
  2. Hosting: Hosting (instance type) in this case Server/Data Center.
  3. Server Address: The address of the Jira Server where Xray is running
  4. Credentials:
    1. Use the Jenkins Credentials Plugin to set the username/password
Warning
titleUpgrading from version below 2.1

If you are upgrading from a version below 2.1, you have to:

  1. Uninstall the old version of the plugin
  2. Go to the Xray configuration section and re-write your instances credentials
  3. Re-save (you don't need to change any data) any Project/Job that is using Xray steps.

...

Info
titleDownload the latest version of the Jenkins Plugin

You may download the latest version of the Jenkins plugin from the latest Release Notes.

If you have the actual xray-for-jira-connector.hpi file,

  1. Go to the Update Center of Jenkins in Manage Jenkins > Manage Plugins.
  2. Select the advanced tab
  3. In the Upload Plugin section, click upload and select the file xray-for-jira-connector.hpi file.

Jenkins Native Installation (via web UI)

Since version 2.1.0, you can install the plugin by using the Jenkins native Web UI. You can read more about how to to it here.

Configuration

Xray for Jenkins is configured in the global settings configuration page  Manage Jenkins > Configure System > Xray for Jira configuration.

Jira servers

The Jira servers configuration defines connections with Jira instances. 

To add a new Jira instance connection, you need to specify some properties:

  1. Configuration alias
  2. Hosting: Hosting (instance type) in this case Server/Data Center.
  3. Server Address: The address of the Jira Server where Xray is running
  4. Credentials:
    1. Use the Jenkins Credentials Plugin to set the username/password (if you are using a Server/Data Center instance) or an API key/secret (if you are using an Cloud instance).
    2. Make sure that the user you are using have the following permissions in the projects where you want to import the results and import/export feature files: View, Edit, Create.

note: the Configuration ID is not editable. This value can be used in the pipelines scripts.


Warninginfo
titleUpgrading from version below 2.1

If you are upgrading from a version below 2.1, you have to:

  1. Go to the Xray configuration section and re-write your instances credentials
  2. Re-save (you don't need to change any data) any Project/Job that is using Xray steps.
Info
titlePlease note

The user present in this configuration must exist in the JIRA instance and have permission to Create Test and Test Execution Issues

Image Removed

Please note

The user present in this configuration must exist in the JIRA instance and have permission to Create Test and Test Execution Issues

Image Added

Creating a new Creating a new Project

The project is where the work that should be performed by Jenkins is configured.

...

Format and specific endpointFieldDescription

Behave JSON multipart

Cucumber JSON multipart

NUnit XML multipart

JUnit XML multipart

Robot XML multipart

TestNG XML multipart

Import to Same Test execution fieldsExecutionWhen this option is check, if you are importing multiple execution report files using a glob expression, the results will be imported to the same Test Execution

Test execution fields

An object (JSON) An object (JSON) specifying the fields for the issue. You may specify the object either directly in the field or in the file path.



Info
titleLearn more

The custom field IDs can be obtained using the Jira REST API Browser tool included in Jira. Each ID is of the form "customfield_ID".

Another option, which does not require Jira administration rights, is to invoke the "Get edit issue meta" in an existing issue (e.g., in a Test issue) as mentioned here.

Example: GET http://yourserver/rest/api/2/issue/CALC-1/editmeta 


NUnit XML

JUnit XML

Robot XML

TestNG XML

Import to Same Test ExecutionWhen this option is check, if you are importing multiple execution report files using a glob expression, the results will be imported to the same Test Execution
Project keyKey of the project where the Test Execution (if the Test Execution Key field wasn't provided) and the Tests (if they aren't created yet) are going to be created
Test execution key

Key of the Test Execution

Test plan keyKey of the Test Plan
Test environmentsList of Test Environments separated by ";"
RevisionSource code's revision being target by the Test Execution
Fix versionThe Fix Version associated with the test execution (it supports only one value)

...

Cucumber

In a typical Cucumber Workflow, after having created a Cucumber project and the Cucumber tests specified in Jira, you may want to have a project that exports the features from Jira, executes the automated tests on a CI environment and then imports back its results.

For this scenario, the Jenkins project would be configured with a set of tasks responsible for:

  1. Pulling the Cucumber project
  2. Exporting Cucumber features from Jira to your Cucumber project
  3. Executing the tests in the CI environment
  4. Importing the execution results back to Jira

Exporting Cucumber features

To start the configuration, add the build step Xray: Cucumber Features Export Task.

Image Removed

After that, configure it.

In this example, we configured the task to extract the features from a set of issues (PROJ-78 and PROJ-79) to the folder that holds the Cucumber project.

Image Removed

Importing Cucumber features

To start the configuration, add the build step Xray: Cucumber Features Import Task.

Image Removed

After that, configure it.

In this example, we configured the task to import to the Project IF of the Xray instance all the .features and .zip files that are contained in \Cucumber directory and sub directories, which were modified in the last 3 hours.

Image Removed

Importing the execution results

To start the configuration, add the post-build action Xray: Results Import Task.

Image Removed

After that, configure it.

In this example, we configured the task to import the Cucumber JSON results back to Jira.

Image Removed

Once all configurations are done, click Save at the bottom of the page.

After running the job, the expected result is a new Test Execution issue created in the Jira instance.

Image Removed

Importing the execution results with user-defined field values

For Cucumber, Behave, JUnit, Nunit and Robot, Xray for Jenkins allows you to create new Test Executions and have control over newly-created Test Execution fields. You can send two files, the normal execution result file and a JSON file similar to the one Jira uses to create new issues. More details regarding how Jira creates new issues here

For this scenario and example, the import task needs to be configured with the Cucumber JSON Multipart format. When selecting this option, you can additionally configure the Test Execution fields in one of two ways:

...

Xray: Build Enviroment Variables

Since version 2.2.0, the Xray plugin will now set some build enviroment variables according to the operation result after each of the Xray Steps mensioned above.


Build Enviroment Variable NameMeaning and Value

XRAY_IS_REQUEST_SUCCESSFUL

Contains the string 'true' if all requests made by the step were sucesseful, or 'false' otherwise.

XRAY_ISSUES_MODIFIED

All Issue keys that were modified and/or created by the step, seperated by ';' with no duplicated entries (E.g. 'CALC-100;CALC-101;CALC-102').

XRAY_RAW_RESPONSE

The unprocessed JSON response of all requests made by the step, seperated by ';'.

XRAY_TEST_EXECS

All Test Execution Issue keys that were modified and/or created by the step, seperated by ';' with no duplicated entries (E.g. 'CALC-200;CALC-201;CALC-202').

Please note that in same cases, it will be not possible to determine the issue type of the Issue key returned in the request response and in that case, the key it will only be added to the XRAY_ISSUES_MODIFIED variable.

XRAY_TEST

All Test Issue keys that were modified and/or created by the step, seperated by ';' with no duplicated entries (E.g. 'CALC-300;CALC-301;CALC-302').

Please note that in same cases, it will be not possible to determine the issue type of the Issue key returned in the request response and in that case, the key it will only be added to the XRAY_ISSUES_MODIFIED variable.

Info
titlePipeline Project Limitations

Due to Jenkins limitations, these variables will not be set on Pipeline projects.

Image Added


Examples

Cucumber

In a typical Cucumber Workflow, after having created a Cucumber project and the Cucumber tests specified in Jira, you may want to have a project that exports the features from Jira, executes the automated tests on a CI environment and then imports back its results.

For this scenario, the Jenkins project would be configured with a set of tasks responsible for:

  1. Pulling the Cucumber project
  2. Exporting Cucumber features from Jira to your Cucumber project
  3. Executing the tests in the CI environment
  4. Importing the execution results back to Jira

Exporting Cucumber features

To start the configuration, add the build step Xray: Cucumber Features Export Task.

Image Added

After that, configure it.

In this example, we configured the task to extract the features from a set of issues (PROJ-78 and PROJ-79) to the folder that holds the Cucumber project.

Image Added

Importing Cucumber features

To start the configuration, add the build step Xray: Cucumber Features Import Task.

Image Added

After that, configure it.

In this example, we configured the task to import to the Project IF of the Xray instance all the .features and .zip files that are contained in \Cucumber directory and sub directories, which were modified in the last 3 hours.

Image Added


Importing the execution results

To start the configuration, add the post-build action Xray: Results Import Task.

Image Added

After that, configure it.

In this example, we configured the task to import the Cucumber JSON results back to Jira.

Image Added

Once all configurations are done, click Save at the bottom of the page.

After running the job, the expected result is a new Test Execution issue created in the Jira instance.

Image Added

Importing the execution results with user-defined field values

For Cucumber, Behave, JUnit, Nunit and Robot, Xray for Jenkins allows you to create new Test Executions and have control over newly-created Test Execution fields. You can send two files, the normal execution result file and a JSON file similar to the one Jira uses to create new issues. More details regarding how Jira creates new issues here

For this scenario and example, the import task needs to be configured with the Cucumber JSON Multipart format. When selecting this option, you can additionally configure the Test Execution fields in one of two ways:

  • Insert the relative path to the JSON file containing the information, or
  • Insert the JSON content directly in the field.

In this example, we configured the following object:

Code Block
languagejs
{
   "fields": {
      "project": {
         "key": "PROJ"
      },
      "summary": "Test Execution for Cucumber results (Generated by job: ${BUILD_TAG})",
      "issuetype": {
         "id": "10102"
      }
   }
}


And configured the task to import the Cucumber JSON Multipart results back to Jira.

Image Added

Once all configurations are done, click Save at the bottom of the page.

After running the job, the expected result is a new Test Execution issue created in the Jira instance, with the Test Execution fields as specified in the Jenkins build step configuration.

Image Added

JUnit

Apart from supporting Cucumber natively, Xray enables you to take advantage of many other testing frameworks like JUnit. In this sense, Xray for Jenkins lets you import results in other formats besides Cucumber JSON.

If you want to import JUnit XML reports, a typical Job outline would be:

  1. Pulling the JUnit project
  2. Executing the tests in the CI environment
  3. Importing the execution results, including Tests, to JIRA

Importing the execution results

To start the configuration, add the post-build action Xray: Results Import Task.

Image Added

After that, configure it.

In this example, we have a configuration where the JUnit XML format is chosen.

Image Added

After running the plan, the expected result is a new Test Execution issue created in the JIRA instance.

Image Added

You can also import multiple results using a glob expression, like in the following example

Image Added

Pipeline projects support

Xray for Jenkins provides support for pipelines projects, allowing you to use Xray specific tasks.

Image Added


Here is a simple example of a pipeline script using the Xray: Cucumber Features Export Task 

Code Block
languagegroovy
titleJenkinsfile example (declarative)
pipeline {
    agent any
    stages {
        stage('Export Cucumber') {
            steps {
               step([$class: 'XrayExportBuilder', filePath: '\\features', issues: 'IF-1', serverInstance: '2ffc3a3e-9e2f-4279-abcd-e9301fe47bed'])
            }
        }
    }
}
Info
titleLearn more

For Pipeline specific documentation, you may want to give a look at:


Examples

JUnit

This is a declarative example, for JUnit based tests.

Code Block
languagegroovy
titleJenkinsfile example (declarative)
pipeline {
    agent any
    stages {
        stage('Compile'){
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [[path: 'java-junit-calc/']]]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'a3285253-a867-4ea7-a843-da349fd36490', url: 'ssh://git@localhost/home/git/repos/automation-samples.git']]])
                sh "mvn clean compile -f java-junit-calc/pom.xml"
            }
        }
        
        stage('Test'){
            steps{
                sh "mvn test -f java-junit-calc/pom.xml"
            }
        }
        
        stage('Import results to Xray') {
            steps {
                step([$class: 'XrayImportBuilder', endpointName: '/junit', fixVersion: 'v3.0', importFilePath: 'java-junit-calc/target/surefire-reports/*.xml', importToSameExecution: 'true', projectKey: 'CALC', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722'])

...

In this example, we configured the following object:

Code Block
languagejs
{
   "fields": {
      "project": {
         "key": "PROJ"
      },
      "summary": "Test Execution for Cucumber results (Generated by job: ${BUILD_TAG})",
      "issuetype": {
         "id": "10102"   }
        }
   }
}

And configured the task to import the Cucumber JSON Multipart results back to Jira.

Image Removed

Once all configurations are done, click Save at the bottom of the page.

After running the job, the expected result is a new Test Execution issue created in the Jira instance, with the Test Execution fields as specified in the Jenkins build step configuration.

Image Removed

JUnit

Apart from supporting Cucumber natively, Xray enables you to take advantage of many other testing frameworks like JUnit. In this sense, Xray for Jenkins lets you import results in other formats besides Cucumber JSON.

If you want to import JUnit XML reports, a typical Job outline would be:

  1. Pulling the JUnit project
  2. Executing the tests in the CI environment
  3. Importing the execution results, including Tests, to JIRA

Importing the execution results

To start the configuration, add the post-build action Xray: Results Import Task.

Image Removed

After that, configure it.

In this example, we have a configuration where the JUnit XML format is chosen.

Image Removed

After running the plan, the expected result is a new Test Execution issue created in the JIRA instance.

Image Removed

You can also import multiple results using a glob expression, like in the following example

Image Removed

Pipeline projects support

Xray for Jenkins provides support for pipelines projects, allowing you to use Xray specific tasks.

Image Removed

Here is a simple example of a pipeline script using the Xray: Cucumber Features Export Task 

 }
}

JUnit multipart

This is a declarative example, for JUnit based tests using the multipart variant/endpoint which allows customization over the Test Execution issue fields.

By changing the value of the endpointName variable, you can easily adapt it for other automation frameworks (e.g. Robot framework, TestNG, NUnit).  

Code Block
languagegroovy
titleJenkinsfile example (declarative)
pipeline {
    agent any
    stages {
        stage('Compile'){
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [[path: 'java-junit-calc/']]]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'a3285253-a867-4ea7-a843-da349fd36490', url: 'ssh://git@localhost/home/git/repos/automation-samples.git']]])
Code Block
languagegroovy
titleJenkinsfile example (declarative)
pipeline {
    agent any
    stages {
        stage('Export Cucumber') {
      sh "mvn clean compile   steps {-f java-junit-calc/pom.xml"
            }
   step([$class: 'XrayExportBuilder', filePath: '\\features', issues: 'IF-1', serverInstance: '2ffc3a3e-9e2f-4279-abcd-e9301fe47bed'])
 }
        
      }  stage('Test'){
        }
    }
}
Info
titleLearn more

For Pipeline specific documentation, you may want to give a look at:

Examples

JUnit

This is a declarative example, for JUnit based tests.

Code Block
languagegroovy
titleJenkinsfile example (declarative)
pipeline {
    agent any
    stages {steps{
                sh "mvn test -f java-junit-calc/pom.xml"
            }
        }
        
        stage('CompileImport results to Xray') {
             steps {
    
            checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: step([[$class: 'SparseCheckoutPathsXrayImportBuilder', sparseCheckoutPathsendpointName: [[path: 'java-junit-calc/']]]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'a3285253-a867-4ea7-a843-da349fd36490', url: 'ssh://git@localhost/home/git/repos/automation-samples.git']]])
   '/junit/multipart', importFilePath: 'java-junit-calc/target/surefire-reports/TEST-com.xpand.java.CalcTest.xml', importInfo: '''{
           "fields": {
             sh "mvn clean compile -f java-junit-calc/pom.xml"
"project": {
                 "key": "CALC"
              },
        }
      "summary": "Test 
Execution for java junit ${BUILD_NUMBER}",
    stage('Test'){
          "issuetype":  steps{
                sh "mvn test -f java-junit-calc/pom.xml"
id": "9"
              },
        }
        "customfield_11807": [
        stage('Import results to Xray') {
     "CALC-1200"
       steps {
      ]
          step([$class: 'XrayImportBuilder', endpointName: '/junit', fixVersion: 'v3.0', importFilePath: 'java-junit-calc/target/surefire-reports/*.xml', importToSameExecution: 'true', projectKey: 'CALC }
        }''', inputInfoSwitcher: 'fileContent', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722'])
            }
        }

    }
}

Cucumber ("standard" workflow)

...