Page History
Table of Contents |
---|
...
Info | ||
---|---|---|
| ||
The Jenkins baseline for this app is v2.60138.3 4 and it may not work properly with previous versions. |
Manual Installation
Info | ||
---|---|---|
| ||
You may download the latest version of the Jenkins plugin from the latest Release Notes. |
...
- Configuration alias
- Hosting: Hosting (instance type) in this case Server/Data Center.
- Server Address: The address of the Jira Server where Xray is running
- Credentials:
- Use the Jenkins Credentials Plugin to set the username/password (if you are using a Server/Data Center instance).
- 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..
- 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.
Notenote: the Configuration ID is not editable. This value can be used in the pipelines scripts.
...
Info | ||
---|---|---|
| ||
The user present in this configuration must exist in the JIRA Jira instance and have permission to Create Test and Test Execution Issues |
...
field | description |
---|---|
Jira instance | The Jira instance where Xray is running |
Credentials | If the above Jira Instance does not have any credential configured, you must define an User scoped credential here |
Issue keys | Set 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. |
...
field | decription |
---|---|
JIRA instance | The Jira instance where Xray is running.Project Key |
Credentials | If the above Jira Instance does not have any credential configured, you must define an User scoped credential here |
Project Key | This is the project where the This is the project where the Tests and Pre-Conditions will be created/updated. |
Cucumber feature files directory | This 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 hours | By 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. |
...
field | description |
---|---|
Jira instance | The Jira instance where Xray is running |
Credentials | If the above Jira Instance does not have any credential configured, you must define an User scoped credential here |
Format | A 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
|
...
Format and specific endpoint | Field | Description | ||||
---|---|---|---|---|---|---|
Behave JSON multipart Cucumber JSON multipart NUnit XML multipart JUnit XML multipart Robot XML multipart TestNG XML multipart | Import to Same Test Execution | When 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) specifying the fields for the issue. You may specify the object either directly in the field or in the file path.
| |||||
Import in parallel | If 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 Robot XML TestNG XML | Import to Same Test Execution | When 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 key | Key of the project where the Test Execution (if the T est 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 key | Key of the Test Plan | |||||
Test environments | List of Test Environments separated by ";" | |||||
Revision | Source code's revision being target by the Test Execution | |||||
Fix version | The Fix Version associated with the test execution (it supports only one value) | |||||
Import in parallel | If 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 enviroment environment variables according to the operation result after each of the Xray Steps mensioned mentioned above.
Build Enviroment Environment Variable Name | Meaning and Value |
---|---|
XRAY_IS_REQUEST_SUCCESSFUL | Contains the string 'true' if all requests made by the step were sucessefulsuccessful, or 'false' otherwise. |
XRAY_ISSUES_MODIFIED | All Issue keys that were modified and/or created by the step, seperated 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, seperated separated by ';'. |
XRAY_TEST_EXECS | All Test Execution Issue keys that were modified and/or created by the step, seperated 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 | All Test Issue keys that were modified and/or created by the step, seperated 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. |
...
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
Code Block | ||||
---|---|---|---|---|
| ||||
pipeline {
agent any
stages {
stage('Export Cucumber') {
steps {
step([$class: 'XrayExportBuilder', filePath: '\\features', issues: 'IF-1', serverInstance: '2ffc3a3e-9e2f-4279-abcd-e9301fe47bed'])
}
}
}
} |
Info | ||
---|---|---|
| ||
For Pipeline specific documentation, you may want to give a look at: |
Examples
JUnit
This is a declarative example, for JUnit based tests.
There are 3 available steps to be used in a Pipeline project:
XrayImportBuilder
-
Import test results (Junit, NUnit, etc...) from your Jenkins job to JiraXrayExportBuilder
-
Export feature files from Jira to your Jenkins job workspaceXrayImportFeatureBuilder
-
Import feature files from Jenkins to Jira
Info | ||
---|---|---|
| ||
For each of the steps mentioned above, you can check the generated syntax reference in the official Jenkins documentation website. |
Step: XrayImportBuilder (import test execution results)
Expand | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Expand | |||||
---|---|---|---|---|---|
| |||||
|
Expand | |||||
---|---|---|---|---|---|
| |||||
|
Expand | |||||||
---|---|---|---|---|---|---|---|
| |||||||
|
Expand | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||
| |||||||||||||||||
Code Block | |||||||||||||||||
| |||||||||||||||||
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{
|
Step: XrayExportBuilder (export cucumber features from Jira to Jenkins)
Expand | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||
|
Expand | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||
Code Block | |||||||||||||
| |||||||||||||
node {
stage('Compile'){
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']]])
|
Expand | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
|
Expand | |||||||||
---|---|---|---|---|---|---|---|---|---|
| |||||||||
|
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).
|
Step: XrayImportFeatureBuilder (import cucumber features from Jenkins to Jira)
Expand | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||
|
Expand | ||||||
---|---|---|---|---|---|---|
| ||||||
| ||||||
Code Block | ||||||
| ||||||
pipeline
|
Expand | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||
|
Info | ||
---|---|---|
| ||
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 | ||||
---|---|---|---|---|
| ||||
pipeline { agent any stages {[[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('Export features }from Xray'){ } stage('Test'){ steps { steps{ checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: sh "mvn test -f java-junit-calc/pom.xml" }false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'a3285253-a867-4ea7-a843-da349fd36490', url: 'ssh://git@localhost/home/git/repos/automation-samples.git']]]) } stage('Import results to Xray') {step([$class: 'XrayExportBuilder', filePath: 'cucumber_xray_tests/features', filter: '11400', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722']) } steps { } step([$class: 'XrayImportBuilder', endpointName: '/junit/multipart', importFilePath: 'java-junit-calc/target/surefire-reports/TEST-com.xpand.java.CalcTest.xml', importInfo: stage('Test''){ "fields": steps{ "project": { sh "cd cucumber_xray_tests && cucumber -x -f json -o data.json" "key": "CALC" } }, "summary": "Test Execution for java junit ${BUILD_NUMBER}", stage('Import results to Xray') { steps { "issuetype": { step([$class: 'XrayImportBuilder', endpointName: '/cucumber', importFilePath: "id": "9"'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 in BDD with Gherkin based frameworks (e.g. Cucumber)).
Code Block | ||||
---|---|---|---|---|
| ||||
pipeline { "customfield_11807": [agent any stages { stage('Synch (update) recent tests "CALC-1200"to Xray'){ steps ]{ } }''checkout([$class: 'GitSCM', inputInfoSwitcherbranches: 'fileContent', serverInstance[[name: '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 | ||||
---|---|---|---|---|
| ||||
pipeline { agent any stages { stage('Export features from Xray'){ steps {*/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']) } 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']]]) } stage('Export features from Xray'){ step([$class: 'XrayExportBuilder', filePath: 'cucumber_xray_tests/features', filter: '11400', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722']) 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']]]) stage('Test'){ sh "rm -rf steps{ cucumber_xray_tests/features" sh "cd step([$class: 'XrayExportBuilder', filePath: 'cucumber_xray_tests && cucumber -x -f json -o data.json"/features', filter: '11400', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722']) } } stage('Import results to XrayTest') { steps { step([$class: 'XrayImportBuilder', endpointName: '/cucumber', importFilePath: 'cucumbersh "cd cucumber_xray_tests/data.json', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722']) && cucumber -x -f json -o data.json" } } } } |
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 | ||||
---|---|---|---|---|
| ||||
pipeline { agent any stages stage('Import results to Xray') { steps { stage('Synch (update) recent tests to Xray'){ step([$class: 'XrayImportBuilder', endpointName: '/cucumber', importFilePath: 'cucumber_xray_tests/data.json', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722']) } steps {} } } |
Using parameters
You can ask for human input in your pipeline builds by passing parameters
Code Block | ||||
---|---|---|---|---|
| ||||
pipeline{ agent any parameters 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']]]{ string(defaultValue: "NTP", description: '', name: 'projectKey') step([$class: 'XrayImportFeatureBuilder', folderPath: 'cucumber_xray_tests/features', lastModified: '10', projectKey: 'CALC', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722']) string(defaultValue: "Android", description: '', name: 'env') } stages { stage ('Import Results') { steps }{ } step([$class: 'XrayImportBuilder', stage('Export features from Xray'){endpointName: '/junit', steps { importFilePath: 'java-junit-calc/target/surefire-reports/*.xml', checkout([$classimportToSameExecution: 'GitSCMtrue', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'a3285253-a867-4ea7-a843-da349fd36490', url: 'ssh://git@localhost/home/git/repos/automation-samples.git']]]) projectKey: params.projectKey, sh "rm -rf cucumber_xray_tests/features" revision: params.projectKey + env.BUILD_NUMBER, step([$class: 'XrayExportBuilder', filePath: 'cucumber_xray_tests/features', filter: '11400', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722'', testEnvironments: params.env]) } } } stage('Test'){ } } |
Recommendations
You can automatically generate your step scripts using the Jenkins Snippet Generator.
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 containerized 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 | ||||||
---|---|---|---|---|---|---|
| ||||||
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 = [ 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 | ||||
---|---|---|---|---|
| ||||
pipeline{ agent any name: 'my Jira server', parameters { string(defaultValue: "NTP", descriptionhostingType: 'SERVER', name: 'projectKey') string(defaultValue: "Android", descriptionurl: 'http://example.com', name: 'env') } stages { credentialId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' // Credential ID from stagethe ('Import ResultsCredentials') {plugin. ], steps {[ step([$class: 'XrayImportBuilder', name: 'my Jira cloud', endpointNamehostingType: '/junitCLOUD', importFilePathcredentialId: 'javaxxxxxxxx-xxxx-junit-calc/target/surefire-reports/*.xml', xxxx-xxxx-xxxxxxxxxxxx' // Credential ID from the 'Credentials' plugin. ] ] importToSameExecution: 'true', projectKey: params.projectKey, revision: params.projectKey + env.BUILD_NUMBER,as JSONArray // ~~~ 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 = instance.optString('hostingType', '') String url = serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722', instance.optString('url', '') String credentialId = instance.optString('credentialId', null) HostingType hostingType = hostingTypeString == testEnvironments'CLOUD' ? HostingType.CLOUD : params.env])HostingType.SERVER xrayInstances.add(new XrayInstance(null, name, hostingType, url, credentialId)) } List<XrayInstance> oldXrayInstances = config.getServerInstances() if (!deleteOldInstances && oldXrayInstances != null) { xrayInstances.addAll(oldXrayInstances) } config.setServerInstances(xrayInstances) config.save() println('Xray Jira Instances } } |
Recommendations
You can automatically generate your step scripts using the Jenkins Snippet Generator.
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.
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.
...