Versions Compared

Key

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

...

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

...

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 do it here.

Configuration

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

Jira Instance

The Jira 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 API key/secret
    2. Make sure that was used to create the API key has the following permissions in the projects where you want to import the results and import/export feature files: View, Edit, Create.
    3. This field is optional - if you don't want to use a System scoped credential to authenticate in your instance, you can leave this field empty and force the users to use an User scoped credential in the build task.

...

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 in the target project

Image Removed

Creating a new Project

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

For this app, you can configure:

  • Freestyle projects
  • Maven Projects
  • Multi-configuration Projects
  • Pipeline Projects

In the home page, clicking for example New Item > Freestyle project, provide a name, and then click OK.

Image Removed

Build Steps

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.

Xray: Cucumber Features Export Task

This build step will export the Cucumber Tests (i.e., Scenario/Scenario Outlines) in .feature or bundled in a .zip file. The rules for exporting are defined here.

It invokes Xray's Export Cucumber Tests REST API endpoint (see more information here).

Configuration

Some fields need to be configured in order to export the Cucumber Tests. As input, you can either specify issue keys (see the endpoint documention here) or the ID of the saved filter in Jira.

...

Filter ID

...

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.

Credential permissions

If you want to ket your Jenkins' users to use their own Jira credentials in each build, you need to make sure that the users that need to configure the jobs have both USE ITEM and USE OWN permissions.

These permissions are not configurable in the Credentials plugin by default, you need to run your Jenkins instance with the following flags enabled:

     -Dcom.cloudbees.plugins.credentials.UseOwnPermission=true -Dcom.cloudbees.plugins.credentials.UseItemPermission=true

After enabling these flags, go to the Credentials plugin configuration page, and give the required users the USE ITEM and USE OWN permissions.

You can read more about these permissions in the official CloudBees documentation.

Jira Instance

The Jira 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 Cloud.
  3. Server Address: The address of the Jira Server where Xray is running
  4. Credentials:
    1. Use the Jenkins Credentials Plugin to set the API key/secret (please check Global Settings: API Keys for more info on creating API keys)
    2. Make sure that was used to create the API key has the following permissions in the projects where you want to import the results and import/export feature files: View, Edit, Create.
    3. This field is optional - if you don't want to use a System scoped credential to authenticate in your instance, you can leave this field empty and force the users to use a User scoped credential in the build task.
    4. To add a new Credential: 

      1. Xray Client ID should be placed in the Username field

      2. Xray Client Secret should be placed in the Password field


Note: the Configuration ID is not editable. This value can be used in the pipeline 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 in the target project


Image Added

Creating a new Project

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

For this app, you can configure:

  • Freestyle projects
  • Maven Projects
  • Multi-configuration Projects
  • Pipeline Projects

On the home page, click for example New Item > Freestyle project, provide a name, and then click OK.

Image Added

Build Steps

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.

Xray: Cucumber Features Export Task

This build step will export the Cucumber Tests (i.e., Scenario/Scenario Outlines) in .feature or bundled in a .zip file. The rules for exporting are defined here.

It invokes Xray's Export Cucumber Tests REST API endpoint (see more information here).

Configuration

Some fields need to be configured in order to export the Cucumber Tests. As input, you can either specify issue keys (see the endpoint documentation here) or the ID of the saved filter in Jira.

fielddescription

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 Xray's Import Cumcumber Tests REST API endpoint (see more information here)

fielddecription
Jira instanceThe Jira instance where Xray is running.
CredentialsIf the above Jira Instance does not have any credential configured, you must define an User scoped credential here
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. Supports both relative and absolute paths.
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, JUnit, XUnit and NUnit, among others.

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

  • JUnit
  • TestNG
  • NUnit
  • XUnit
  • Robot framework

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

Configuration 

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 Xray's Import Cucumber Tests REST API endpoint (see more information here)

fielddescription
Jira instanceThe Jira instance where Xray is running.
CredentialsIf the above Jira Instance does not have any credential configured, you must define an User scoped credential here
FormatA list of test result formats and its specific endpoint
Execution Report File

The results relative or absolute file path.

Note: glob expressions are supported for

  • JUnit
  • JUnit Multipart
  • TestNG
  • TestNG Multipart
  • NUnit
  • NUnit Multipart
  • XUnit
  • XUnit Multipart
  • Robot framework
  • Robot framework Multipart

Additional fields

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

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. Supports both relative and absolute paths.
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, JUnit, XUnit and NUnit, among others.

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

  • JUnit
  • TestNG
  • NUnit
  • XUnit
  • 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
CredentialsIf the above Jira Instance does not have any credential configured, you must define an User scoped credential here
FormatA list of test result formats and its specific endpoint
Execution Report File

The results relative or absolute file path.

Note: glob expressions are supported for

  • JUnit
  • JUnit Multipart
  • TestNG
  • TestNG Multipart
  • NUnit
  • NUnit Multipart
  • XUnit
  • XUnit Multipart
  • Robot framework
  • Robot framework Multipart

Additional fields

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

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

format and specific endpointfielddescription

Cucumber JSON multipart

NUnit XML multipart

JUnit XML multipart

XUnit XML multipart

Robot XML multipart

TestNG XML multipart

format and specific endpointfielddescription

Cucumber JSON multipart

NUnit XML multipart

JUnit XML multipart

XUnit XML multipart

Robot XML multipart

TestNG XML multipart

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

Test execution fields

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 https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}/editmeta

Warning
titleTest Fields

Please notice that currently only the Test Execution Fields are supported. If you need to use the Test Field you may need to make a direct call (e.g. using CURL) to our REST API.

Import in parallelIf there are several result files, when this checkbox is selected, we will import all the files in parallel (using all available CPU cores)

NUnit XML

JUnit XML

XUnit 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 ExecutionProject 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 createdTest execution key

Key of the Test Execution

Test plan keyKey of the Test PlanTest environmentsList of Test Environments separated by ";"RevisionSource code's revision being target by the Test Execution

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 https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}/editmeta

Warning
titleTest Fields

Please notice that currently only the Test Execution Fields are supported. If you need to use the Test Field you may need to make a direct call (e.g. using CURL) to our REST API.

Fix versionThe Fix Version associated with the test execution (it supports only one value)

Import in parallelIf there are several result files, when this checkbox is selected, we will import all the files in parallel (using all available CPU cores)

Xray: Build Environment Variables

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


NUnit XML

JUnit XML

XUnit 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)
Import in parallelIf there are several result files, when this checkbox is selected, we will import all the files in parallel (using all available CPU cores)

Xray: Build Environment Variables

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


All Test
Build Environment Variable NameMeaning and Value

XRAY_IS_REQUEST_SUCCESSFUL

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

XRAY_ISSUES_MODIFIED

All
Build Enviroment Variable NameMeaning and Value

XRAY_IS_REQUEST_SUCCESSFUL

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

XRAY_ISSUES_MODIFIED

All Issue keys that were modified and/or created by the step, separated 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, separated by ';'.

XRAY_TEST_EXECS

All Test Execution Issue keys that were modified and/or created by the step, separated 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

Issue keys that were modified and/or created by the step, separated 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, separated by ';'.

XRAY_TEST_EXECS

All Test Execution Issue keys that were modified and/or created by the step, separated by ';' with no duplicated entries (E.g. 'CALC-200300;CALC-301201;CALC-302202').

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, separated 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

Info
titlePipeline Project Limitations

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


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.

...

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

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


There are 3 available steps to be used in a Pipeline project:

  • XrayImportBuilder - Import test results (Junit, NUnit, etc...) from your Jenkins job to Jira
  • XrayExportBuilder- Export feature files from Jira to your Jenkins job workspace

  • XrayImportFeatureBuilder - Import feature files from Jenkins to Jira


Info
titleGenerated syntax helper

For each of the steps mentioned above, you can check the generated syntax reference in the official Jenkins documentation website.

Note
iconfalse
titleSee and try some examples by yourself
typeInfo

Please see a tutorial with working Examples using Jenkins pipeline, showcasing different scenarios, which you can download and try by yourself.

Step: XrayImportBuilder (import test execution results)


Expand
titleParameters
ParameterRequired?TypeDescription
serverInstanceYesStringThe ID of the Jira instance configured in the Jenkins System Configuration
endpointNameYesString

The result file type to be imported. Allowed Values:

  • "" (Xray Json format)
  • "/multipart"  (Xray JSON multipart format)
  • "/cucumber"
  • "/cucumber/multipart"
  • "/behave"
  • "/behave/multipart"
  • "/junit"
  • "/junit/multipart"
  • "/nunit"
  • "/nunit/multipart"
  • "/robot"
  • "/robot/multipart"
  • "/bundle" (import of zip file with several cucumber results)
  • "/testng"
  • "/testng/multipart"
  • "/xunit"
  • "/xunit/multipart"

Please note that not all endpoints are available for Jira Sever/Cloud. Please refer to the REST API documentation to see what is available in your instance.

projectKeyYesStringThe Jira project key where you want to import your results
importFilePathYesString

File path where the result files can be found.

credentialIdYes, if the Jira instance was configured without credentials in System ConfigurationStringCredential ID from the Credentials plugin to be used to authenticate the Jira requests
testEnvironmentsNoString

Test environments to be added to the Test Execution issue, separated by ";".

(warning) This value will only be used if the endpointName is not multipart

testPlanKeyNoString

All Tests will be added to the given Test Plan key, if provided.

(warning) This value will only be used if the endpointName is not multipart

fixVersionNoString

Fix version to be added to the Test Execution issue.

(warning) This value will only be used if the endpointName is not multipart

testExecKeyNoString

Key of the test Execution issue to be updated. Leave empty to create a new issue with the import.

(warning) This value will only be used if the endpointName is not multipart

revisionNoString

Source code and documentation version used in the test execution.

(warning) This value will only be used if the endpointName is not multipart

importInfoYes, if multipart endpointStringFile path to the Test Execution info file OR JSON String with the info.
inputInfoSwitcherYes, if importInfo is being usedString

Allowed values:

  • "filePath" - if importInfo field is used and represents a file path
  • "fileContent" - if importInfo field is used and represents a JSON text
testImportInfoNoStringFile path to the Test info file.
inputTestInfoSwitcherYes, if testImportInfo is being usedString

Allowed values:

  • "filePath" - if testImportInfo field is used and represents a file path
  • "fileContent" - if testImportInfo field is used and represents a JSON text
importToSameExecutionNoString

Allowed values:

  • "true" - to import all created tests and linked them to a single Test Execution issue
  • "" - link a Test Execution issue to every imported Test issue
importInParallelNoString

Allowed values:

  • "true" - to import all result files (if there are multiple) in parallel, in order to speed up the import process
  • "" - to import all result files (if there are multiple) sequentially
Expand
titleExample: simple Junit multi-file result import
Code Block
languagegroovy
        stage('Import results to Xray') {
            steps {
                step([$class: 'XrayImportBuilder', endpointName: '/junit', importFilePath: 'java-junit-calc/target/surefire-reports/*.xml', importToSameExecution: 'true', projectKey: 'CALC', serverInstance: 'ecc67055-c359-40cb-8b8a-a44cb9f6ca30'])
            }
        }
Expand
titleExample: xUnit result import with optional fields
Code Block
languagegroovy
        stage('Import results to Xray') {
            steps {
                step([$class: 'XrayImportBuilder', endpointName: '/xunit', importFilePath: '/reports/*.xml', importToSameExecution: 'true', projectKey: 'CALC', serverInstance: 'ecc67055-c359-40cb-8b8a-a44cb9f6ca30', importInParallel: '', fixVersion: 'v3.0', testEnvironments: 'linux;firefox', testPlanKey: 'CALC-123', testExecKey: 'CALC-456', revision: 'commit eccc5855b', credentialId: '26dba0be-45ca-4ffd-b959-13dbd241aa82'])
            }
        }
Expand
titleExample: Nunit multipart result import
Code Block
languagegroovy
        stage('Import results to Xray (multipart)') {
            steps {
                step([$class: 'XrayImportBuilder', endpointName: '/nunit/multipart', importFilePath: '/reports/*.xml', importToSameExecution: 'true', projectKey: 'CALC', serverInstance: 'ecc67055-c359-40cb-8b8a-a44cb9f6ca30', importInParallel: 'true', importInfo: '/info/my-test-exec-info.json', inputInfoSwitcher: 'filePath' ])
            }
        }
Info

importInfo must comply with the same format as the Jira issue create/update REST API format

Expand
titleExample: Nunit multipart result import with Test info and using environment variables
Code Block
languagegroovy
        stage('Import results to Xray (multipart)') {
            steps {
                step([$class: 'XrayImportBuilder', endpointName: '/nunit/multipart', importFilePath: '/reports/*.xml', importToSameExecution: 'true', projectKey: 'CALC', serverInstance: 'ecc67055-c359-40cb-8b8a-a44cb9f6ca30', importInParallel: 'true', importInfo: '/info/my-test-exec-info.json', inputInfoSwitcher: 'filePath', inputTestInfoSwitcher: 'fileContent', testImportInfo: '''{
           "fields": {
              "project": {
                 "key": "CALC"
              },
              "summary": "Test Execution for java junit ${BUILD_NUMBER}",
              "issuetype": {
                 "id": "9"
              },
              "customfield_11807": [
                 "CALC-1200"
              ]
           }
        }'''])
            }
        }
Info

importInfo and testImportInfo must comply with the same format as the Jira issue create/update REST API format

Step: XrayExportBuilder (export cucumber features from Jira to Jenkins)


Expand
titleParameters
ParameterRequired?TypeDescription
serverInstanceYesStringThe ID of the Jira instance configured in the Jenkins System Configuration
issues

Yes

(not required if filter is used)

String

Xray Tests/Test Plans/Test Sets/Test Execution issue keys, separated by ';'.

filter

Yes

(not required if issues is used)

StringThe Jira filter ID containing Xray Tests/Test Plans/Test Sets/Test Execution issues
filePathNoString

The default value is "/features"

File path where the feature files will be downloaded

credentialIdYes, if the Jira instance was configured without credentials in System ConfigurationStringCredential ID from the Credentials plugin to be used to authenticate the Jira requests
Expand
titleExample: Export features from filter to default folder
Code Block
languagegroovy
        stage('Export feature files') {
            step([$class: 'XrayExportBuilder', filter: '12345', serverInstance: 'ecc67055-c359-40cb-8b8a-a44cb9f6ca30'])
        }
Expand
titleExample: Export features from issues to custom folder (with user's credentials)
Code Block
languagegroovy
        stage('Export feature files') {
            step([$class: 'XrayExportBuilder', issues: 'CALC-123;CALC-234;CALC-345', serverInstance: 'ecc67055-c359-40cb-8b8a-a44cb9f6ca30', credentialId: '26dba0be-45ca-4ffd-b959-13dbd2410a82', filePath: 'my/feature/folder'])
        }
Expand
titleExample: Export features using variables
Code Block
languagegroovy
        stage('Export feature files') {
            step([$class: 'XrayExportBuilder', issues: '${MY_ISSUE_KEYS}', filter: '${MY_FILTER_ID}', filePath: '${MY_FILE_PATH}', serverInstance: 'ecc67055-c359-40cb-8b8a-a44cb9f6ca30', credentialId: '26dba0be-45ca-4ffd-b959-13dbd2410a82'])
        }

Step: XrayImportFeatureBuilder (import cucumber features from Jenkins to Jira)


Expand
titleParameters
ParameterRequired?TypeDescription
serverInstanceYesStringThe ID of the Jira instance configured in the Jenkins System Configuration
folderPathYesStringThis is the directory containing your feature files. All the files in this directory and sub directories will be imported.
credentialIdYes, if the Jira instance was configured without credentials in System ConfigurationStringCredential ID from the Credentials plugin to be used to authenticate the Jira requests
projectKeyYesStringThis is the project where the Tests and Pre-Conditions will be created/updated.
testInfoNoStringFile path to the Test info file that will be used to create the new Test issues.
preconditionsNoStringFile path to the Preconditions info file that will be used to create the new Precondition issues.
lastModifiedNoStringBy 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.
Expand
titleExample: Import features modified in the last day
Code Block
languagegroovy
        stage('Export feature files') {
            step([$class: 'XrayImportFeatureBuilder', folderPath: '/my/feature/folder', lastModified: '24', projectKey: 'CALC', serverInstance: 'ecc67055-c359-40cb-8b8a-a44cb9f6ca30'])
        }
Expand
titleExample: Import features with test info and preconditions info
Code Block
languagegroovy
        stage('Export feature files') {
            step([$class: 'XrayImportFeatureBuilder', credentialId: 'f5522808-5cfa-4cd4-8972-8059f80cb3ed', folderPath: '/my/feature/folder', preconditions: '/path/to/precond/precondinfo.json', projectKey: 'CALC', serverInstance: 'ecc67055-c359-40cb-8b8a-a44cb9f6ca30', testInfo: '/path/to/testInfo/tesinfo.json'])
        }





Info
titleLearn more

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


Cucumber Workflow suggestions

Cucumber ("standard" workflow)

This is a declarative example, for Cucumber tests using the "standard" workflow (see Testing in BDD with Gherkin based frameworks (e.g. Cucumber)).

Code Block
languagegroovy
titleJenkinsfile example (declarative)
pipeline
Code Block
languagegroovy
titleJenkinsfile example (declarative)
pipeline {
    agent any
    stages {
        stage('Export features from CucumberXray') {
            steps {
               step checkout([$class: 'XrayExportBuilderGitSCM', filePath branches: [[name: '\\features', issues: 'IF-1', serverInstance: '2ffc3a3e-9e2f-4279-abcd-e9301fe47bed'*/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',   }
    }
}
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 {filePath: 'cucumber_xray_tests/features', filter: '11400', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722'])
            }
        }
        
        stage('CompileTest'){
            steps {
{
                sh "cd cucumber_xray_tests && cucumber -x -f json -o data.json"
            }
     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']]]) }
        
        stage('Import results to Xray') {
            steps {
    sh "mvn clean compile -f java-junit-calc/pom.xml"
       step([$class: 'XrayImportBuilder', endpointName: '/cucumber',  }
    importFilePath: 'cucumber_xray_tests/data.json', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722'])
    }
        }
        stage('Test'){}
    }
}

Cucumber ("VCS/Git based" workflow)

This is a declarative example, for Cucumber tests using the "VCS/Git based" workflow (see Testing in BDD with Gherkin based frameworks (e.g. Cucumber)).

Code Block
languagegroovy
titleJenkinsfile example (declarative)
pipeline         steps{
    agent any
    stages {
      sh "mvn test -f java-junit-calc/pom.xml"
     stage('Synch (update) recent tests to Xray'){
        }
    steps    }{
        
        stage('Import results 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: 'XrayImportBuilderXrayImportFeatureBuilder', endpointNamefolderPath: '/junit', fixVersion: 'v3.0', importFilePath: 'java-junit-calc/target/surefire-reports/*.xmlcucumber_xray_tests/features', importToSameExecutionlastModified: 'true10', 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 in BDD with Gherkin based frameworks (e.g. 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']]])
                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'])
            }
        }
    }
}

Cucumber ("VCS/Git based" workflow)

Using parameters


You can ask for human input in your pipeline builds by passing parametersThis is a declarative example, for Cucumber tests using the "VCS/Git based" workflow (see Testing in BDD with Gherkin based frameworks (e.g. Cucumber)).

Code Block
languagegroovy
titleJenkinsfile example (declarative)Parameters usage
pipeline {
    agent any
    stagesparameters {
         stage('Synch (update) recent tests to Xray'){
            steps {
     string(defaultValue: "NTP", description: '', name: 'projectKey')
        string(defaultValue:   checkout([$class"Android", description: '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']]])env')
    }
    stages {
        stage ('Import Results') {
            steps {
                step([$class: 'XrayImportFeatureBuilderXrayImportBuilder', folderPath 
                endpointName: 'cucumber_xray_tests/featuresjunit', 
 lastModified: '10', projectKey: 'CALC', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722'])
          importFilePath:  }
'java-junit-calc/target/surefire-reports/*.xml', 
         }
       importToSameExecution: 'true', 
        stage('Export features from Xray'){
     projectKey: params.projectKey,
      steps {
         revision: params.projectKey + env.BUILD_NUMBER,
    checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsIdserverInstance: 'a3285253552d0cb6-a8676f8d-4ea748ba-a843bbad-da349fd3649050e94f39b722', url: 'ssh://git@localhost/home/git/repos/automation-samples.git']]
                testEnvironments: params.env])
            }
    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'])
    }
}


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. 

Jira instances configuration via Groovy script (Jenkins Script Console)

If you use a containerised version of Jenkins, or simply want to avoid creating the Jira configurations manually (using the Jenkins UI), you can use the following script in the Jenkins Script Console.

To use the script below, you just need to modify the contents of the instances and deleteOldInstances variables.

Code Block
languagegroovy
firstline1
titleCreate new Jira instances in Xray global configuration
import jenkins.model.Jenkins
import net.sf.json.JSONArray
import net.sf.json.JSONObject
import com.xpandit.plugins.xrayjenkins.model.HostingType
import com.xpandit.plugins.xrayjenkins.model.XrayInstance
import com.xpandit.plugins.xrayjenkins.model.ServerConfiguration

// true, if you want the old Jira instances removed, false otherwise.
boolean deleteOldInstances = false

/* Represents the Jira instances to be added to the Global Jenkins configuration.
 * - name: the name of the Jira instance to be displayed to the users.
 * - hostingType: must be one of two values. 'SERVER' for Server or Data Center instances OR 'CLOUD' for cloud instances.
 * - url: [ONLY FOR SERVER INSTANCES] the base URL/IP of the Jira server address.
 * - credentialId: [OPTIONAL] the credential ID from the 'Credentials' plugin that will be used to authenticate the jira REST API requests.
 */
JSONArray instances = [
        }[
        }
      }
}

Using parameters

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

Code Block
languagegroovy
titleParameters usage
pipeline{
    agent any
  name: 'my Jira server',
     parameters {
        string(defaultValue: "NTP", descriptionhostingType: 'SERVER', name: 'projectKey')

           string(defaultValue: "Android", description: '', name: 'env')     url: 'http://example.com',
    }
    stages {
        stagecredentialId: ('Import Results') {
            steps {'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' // Credential ID from the 'Credentials' plugin.
        ],
        step([$class: 'XrayImportBuilder',  [
                endpointNamename: '/junitmy Jira cloud', 
                importFilePathhostingType: 'java-junit-calc/target/surefire-reports/*.xmlCLOUD', 
                importToSameExecutioncredentialId: 'true', 
    xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' // Credential ID from the 'Credentials' plugin.
        ]
] as JSONArray

// ~~~ projectKey: params.projectKey,
                revision: params.projectKey + env.BUILD_NUMBER,Saves the new Jira instances into the Jenkins global configuration ~~~
ServerConfiguration config = ServerConfiguration.get()
List<XrayInstance> xrayInstances = new ArrayList<XrayInstance>()

instances.each {instance ->
    String name = instance.optString('name', '')
    String hostingTypeString =  serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722',instance.optString('hostingType', '')
    String url    = instance.optString('url', '')
    String credentialId  testEnvironments: params.env])= instance.optString('credentialId', null)

    HostingType hostingType = hostingTypeString == 'CLOUD' ? HostingType.CLOUD : }HostingType.SERVER

    xrayInstances.add(new XrayInstance(null, name, hostingType, url, credentialId))
}

List<XrayInstance> oldXrayInstances = config.getServerInstances()
if (!deleteOldInstances && oldXrayInstances != null)   }{
    }
}

Recommendations

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

Image Removed

Image Removed

...

xrayInstances.addAll(oldXrayInstances)
}

config.setServerInstances(xrayInstances)
config.save()

println('Xray Jira Instances created :)')


Troubleshooting

The build process is failing with status code 403

...

If you are a Jira administrator, you can go to Jira administration > User Management and reset the failed login.

The Jira xxx configuration of this

...

task was not found

If you obtain this error, probably you have migrated from an old version of this plugin. You need to open each project/job configuration and save it.

...