Versions Compared

Key

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

Image Modified

Table of Contents
 

...

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


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.


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 enviroments to be added to the Test Execution issue, seperated 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 Exeution 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 {
                
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
ecc67055-
6f8d
c359-
48ba
40cb-
bbad
8b8a-
50e94f39b722
a44cb9f6ca30'])
            }
        }
} }
Jenkinsfile example (scripted)
Expand
titleExample: xUnit result import with optional fields
Code Block
languagegroovy
title
node
 
{
       stage('
Compile
Import results to Xray') {
            steps {
                
checkout
step([$class: '
GitSCM
XrayImportBuilder', 
branches
endpointName: 
[[name
'/xunit', importFilePath: '
*/master']]
/reports/*.xml', 
doGenerateSubmoduleConfigurations
importToSameExecution: 
false
'true', 
extensions: [[$class
projectKey: '
SparseCheckoutPaths
CALC', 
sparseCheckoutPaths
serverInstance: 
[[path: 'java-junit-calc/']]]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'a3285253-a867-4ea7-a843-da349fd36490', url: 'ssh://git@localhost/home/git/repos/automation-samples.git']]]
'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'])
            }
    
sh
 
"mvn
 
clean
 
compile -f java-junit-calc/pom.xml"
 }
Expand
titleExample: Nunit multipart result import
Code Block
languagegroovy
        
} stage('Test')
stage('Import results to Xray (multipart)') {
            
try
steps {
                
sh "mvn test -f java-junit-calc/pom.xml" } catch (ex) {
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' ])
            
echo 'Something failed'
}
        }
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
throw ex
Code Block
languagegroovy
        stage('Import results to 
}
Xray (multipart)') {
       
}
     steps 
stage('Import results to Xray') {
{
                step([$class: 'XrayImportBuilder', endpointName: '/nunit/
junit
multipart', 
fixVersion
importFilePath: '
v3.0
/reports/*.xml', 
importFilePath
importToSameExecution: '
java-junit-calc/target/surefire-reports/*.xml', importToSameExecution: 'true', projectKey: 'CALC', serverInstance: '552d0cb6-6f8d-48ba-bbad-50e94f39b722'])
true', projectKey: 'CALC', serverInstance: 'ecc67055-c359-40cb-8b8a-a44cb9f6ca30', importInParallel: 'true', importInfo: '/info/my-test-exec-info.json', inputInfoSwitcher: 'filePath', inputTestInfoSwitcher: 'fileContent', testImportInfo: '''{
          
} }

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 {
 "fields": {
         
agent
 
any
    
stages
"project": {
        
stage('Compile'){
         "key": "CALC"
    
steps
 
{
         },
       
checkout([$class:
 
'GitSCM',
 
branches:
 
[[name:
 
'*/master']],
 
doGenerateSubmoduleConfigurations:
 
false,
 
extensions
"summary": 
[[$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']]])
"Test Execution for java junit ${BUILD_NUMBER}",
              "issuetype": {
                
sh
 "
mvn clean compile -f java-junit-calc/pom.xml"
id": "9"
              },
        
}
      "customfield_11807": [
 
        
stage('Test'){
        
steps{
"CALC-1200"
              
sh "mvn test -f java-junit-calc/pom.xml"
]
           
}
        }
stage('Import results to Xray') {
'''])
            
steps {
}
        
step([$class: 'XrayImportBuilder', endpointName: '/junit/multipart', importFilePath: 'java-junit-calc/target/surefire-reports/TEST-com.xpand.java.CalcTest.xml', importInfo: '''{ "fields": { "project": { "key": "CALC"
}
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, seperated 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'])
  
"summary": "Test Execution for java junit ${BUILD_NUMBER}", "issuetype": { "id": "9"
      }
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 
}, "customfield_11807": [
feature files') {
            step([$class: 'XrayImportFeatureBuilder', folderPath: '/my/feature/folder', 
"CALC-1200"
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') {
   
}
        
}''', inputInfoSwitcher
 step([$class: '
fileContent
XrayImportFeatureBuilder', 
serverInstance
credentialId: '
552d0cb6
f5522808-
6f8d
5cfa-
48ba
4cd4-
bbad
8972-
50e94f39b722
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)

...

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

...