Jenkins Xray集成报错:Test Execution类型Jira Issue被误判
Jenkins Xray集成报错:Issue key带转义单引号导致400错误
问题场景
Jenkins流水线中配置Xray测试结果导入步骤,代码如下:
step([$class: 'XrayImportBuilder', endpointName: '/xunit', fixVersion: '1.0', importFilePath: '/MyFirstUnitTests/TestResults.xml', importToSameExecution: 'true', testExecKey: 'TSTLKS-753', serverInstance: '9146a388-e399-4e55-be28-8c65404d6f9d', credentialId:'75287529-134d-4s91-9964-7h740d8d2i63'])
执行时触发400错误:
ERROR: Unable to confirm Result of the upload..... Upload Failed!
Status:400 Response:{"error":"Issue with key \u0027TSTLKS-753\u0027 does not exist or is not of type Test Execution."}
确认TSTLKS-753确实是Test Execution类型,但请求中Issue key被自动添加了转义单引号\u0027,尝试替换双引号或删除引号仍无效。
解决方案
1. 用变量存储Issue key后传入
Groovy中直接写字符串常量可能被插件额外转义,改用变量存储后传入:
def testExecKey = 'TSTLKS-753' step([$class: 'XrayImportBuilder', endpointName: '/xunit', fixVersion: '1.0', importFilePath: '/MyFirstUnitTests/TestResults.xml', importToSameExecution: 'true', testExecKey: testExecKey, serverInstance: '9146a388-e399-4e55-be28-8c65404d6f9d', credentialId:'75287529-134d-4s91-9964-7h740d8d2i63'])
2. 升级Xray Jenkins插件到最新稳定版
部分旧版本Xray插件存在字符串转义bug,尤其是处理testExecKey参数时。前往Jenkins插件管理页面,找到Xray for Jira插件,升级到官方最新稳定版本后重试。
3. 绕过插件,直接调用Xray REST API
如果插件问题无法解决,用httpRequest步骤直接调用Xray API导入测试结果:
// 读取测试结果文件内容 def testResults = readFile file: '/MyFirstUnitTests/TestResults.xml' // 调用Xray API导入到指定Test Execution httpRequest authentication: '75287529-134d-4s91-9964-7h740d8d2i63', contentType: 'application/xml', httpMode: 'POST', url: 'https://你的Jira域名/rest/raven/1.0/import/xunit?testExecKey=TSTLKS-753&fixVersion=1.0', requestBody: testResults
注意替换https://你的Jira域名为实际地址,确保凭证有Xray API调用权限。
4. 用流水线语法生成器重新生成步骤
通过Jenkins内置工具生成代码,避免手动编写的语法隐式问题:
- 进入Jenkins项目 → 流水线语法 → 选择"step: General Build Step" → 选择"Xray: Import Results"
- 手动填写所有参数,生成代码后直接替换原有步骤。
内容的提问来源于stack exchange,提问作者Claudia Martins
相关产品推荐
相关产品推荐

