Versions Compared

Key

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

...

The installation is made manually. For more information on how to install add-ons, please refer to how to install add-ons.


Info
titleRequirements

This app was tested against Jenkins The Jenkins baseline for this app is v2.3260.x 3 and it may not work properly with previous versions. 

...

  1. Configuration alias
  2. Server Address: The address of the Jira Server where Xray is running
  3. Authentication:
    1. User: username
    2. Password.

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

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 Added

Creating a new Project

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

...

Build steps are the building blocks of the build process. These need to be defined in the project configuration.

The app provides

  • one build step for exporting Cucumber Scenario/Scenario Outlines from Jira as .feature files

...

  • one build step for importing Cucumber Tests from existing Cucumber features into Jira.
  • one post-build action which publishes the execution results back to Jira, regardless of the build process status.


Info
titlePlease note
The fields of the tasks may take advantage of the Jenkins Environment variables, which can be used to populate fields such as the "Revision" for specifying the source code's revision. For more information, please see Jenkins set environment variables.

...

fielddescription
Jira instanceThe Jira instance where Xray is running
Issue keysSet of issue keys separated by ";"

Filter ID

A number that indicates the filter ID
File path

The relative path of the directory where the features should be exported to; normally, this corresponds to the "features" folder of the Cucumber project that has the implementation steps. Note: The directory will be created if it does not exist.

Xray:

...

Cucumber Features Import Task

This build step will import existing cucumber Tests from existing Cucumber feature files into Xray issues. This Task will import from .feature files and also from .zip files.

It invokes The app provides easy access to Xray's Import Execution Results Cumcumber Tests REST API endpoints endpoint (see more information here). Therefore, it mimics the endpoints input parameters.

It supports importing results in Xray's own JSON format, Cucumber, Behave, JUnit, and NUnit, among others.

Configuration 

fielddecription
JIRA
fielddescription
Jira instanceThe Jira instance where Xray is running.
FormatA list of test result formats and its specific endpoint
Execution Report File

The results relative file path

Note: regex is not supported.

Additional fields

Depending on the chose test result format and endpoint, some additional fields may need to be configured.

...

Behave JSON multipart

Cucumber JSON multipart

NUnit XML multipart

JUnit XML multipart

Robot XML multipart

...

Test execution fields

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 

Project KeyThis is the project where the Tests and Pre-Conditions will be created/updated.
Cucumber feature files directoryThis is the directory containing your feature files. All the files in this directory and sub directories will be imported.
Modified in the last hoursBy entering an integer n here, only files that where modified in the last n hours will be imported. 
Leave empty if you do not want to use this parameter.


Xray: Results Import Task

The app provides easy access to Xray's Import Execution Results REST API endpoints (see more information here). Therefore, it mimics the endpoints input parameters.

It supports importing results in Xray's own JSON format, Cucumber, Behave, JUnit, and NUnit, among others.

Using a glob expression, you can import multiple results files in the following formats:

  • JUnit
  • TestNG
  • NUnit
  • Robot framework

For those formats, the file path needs to be relative to the workspace.

Configuration 

fielddescription
Jira instanceThe Jira instance where Xray is running
FormatA list of test result formats and its specific endpoint
Execution Report File

The results relative file path

Note: glob expressions are supported for

  • JUnit
  • TestNG
  • NUnit
  • Robot framework

Additional fields

Depending on the chose test result format and endpoint, some additional fields may need to be configured.

format and specific endpointfielddescription

Behave JSON multipart

Cucumber JSON multipart

NUnit XML multipart

JUnit XML multipart

Robot XML multipart

TestNG XML multipart

Test execution fields

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)


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'])
            }
        }
    }
}

Cucumber ("standard" workflow)

This is a declarative example, for Cucumber tests using the "standard" workflow (see Testing with Cucumber).

Code Block
languagegroovy
titleJenkinsfile example (declarative)
pipeline {
    agent any
    stages {
        stage('Export features from Xray'){
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'a3285253-a867-4ea7-a843-da349fd36490', url: 'ssh://git@localhost/home/git/repos/automation-samples.git']]])
                step([$class: 'XrayExportBuilder', filePath: 'cucumber_xray_tests/features', filter: '11400', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722'])
            }
        }
        
        stage('Test'){
            steps{
                sh "cd cucumber_xray_tests && cucumber -x -f json -o data.json"
            }
        }
        
        stage('Import results to Xray') {
            steps {
                step([$class: 'XrayImportBuilder', endpointName: '/cucumber', importFilePath: 'cucumber_xray_tests/data.json', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722'])
            }
        }
    }
}

Cucumber ("VCS/Git based" workflow)

This is a declarative example, for Cucumber tests using the "VCS/Git based" workflow (see Testing with Cucumber).

Code Block
languagegroovy
titleJenkinsfile example (declarative)
pipeline {
    agent any
    stages {
         stage('Synch (update) recent tests to Xray'){
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'a3285253-a867-4ea7-a843-da349fd36490', url: 'ssh://git@localhost/home/git/repos/automation-samples.git']]])
                step([$class: 'XrayImportFeatureBuilder', folderPath: 'cucumber_xray_tests/features', lastModified: '10', projectKey: 'CALC', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722'])
            }
        }
        
        stage('Export features from Xray'){
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'a3285253-a867-4ea7-a843-da349fd36490', url: 'ssh://git@localhost/home/git/repos/automation-samples.git']]])
                sh "rm -rf cucumber_xray_tests/features"
                step([$class: 'XrayExportBuilder', filePath: 'cucumber_xray_tests/features', filter: '11400', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722'])
            }
        }
        
        stage('Test'){
            steps{
                sh "cd cucumber_xray_tests && cucumber -x -f json -o data.json"
            }
        }
        
        stage('Import results to Xray') {
            steps {
                step([$class: 'XrayImportBuilder', endpointName: '/cucumber', importFilePath: 'cucumber_xray_tests/data.json', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722'])
            }
        }
    }
}

Using parameters

You can ask for human input in your pipeline builds by passing parameters

Code Block
languagegroovy
titleParameters usage
pipeline{
    agent any
    parameters {
        string(defaultValue: "NTP", description: '', name: 'projectKey')
        string(defaultValue: "Android", description: '', name: 'env')
    }
    stages {
        stage ('Import Results') {
            steps {
                step([$class: 'XrayImportBuilder', 
                endpointName: '/junit', 
                importFilePath: 'java-junit-calc/target/surefire-reports/*.xml', 
                importToSameExecution: 'true', 
                projectKey: params.projectKey,
                revision: params.projectKey + env.BUILD_NUMBER,
                serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722',
                testEnvironments: params.env])
            }
            
        }
    }
}


Recommendations

You can automatically generate your step scripts using the Jenkins Snippet Generator.

Image Added

Image Added

This is the simplest way to generate your step script, and we strongly recommend the use of this snippet due to the complexity of some task related parameters. 

NUnit XML

JUnit XML

Robot XML

...

Key of the Test Execution

...

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 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:

...

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

Troubleshooting

...