You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

上传JUnit XML至Xray时如何更新Jira Xray执行摘要?

如何更新Xray测试执行的名称/摘要(JUnit XML + Jenkins流水线场景)

当前你使用的XrayImportBuilder Jenkins步骤确实没有直接设置测试执行名称/摘要的参数,但可以通过以下两种方式实现需求:

方法一:修改JUnit XML自定义执行元数据

Xray支持通过JUnit XML中的自定义属性来指定测试执行的名称和摘要,只需在<testsuite>节点下添加对应的property即可:

修改你的testim-tests-report2.xml,在<testsuite>内部添加执行相关的自定义属性:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<testsuites>
  <testsuite name="selenium run" tests="1" failure="1" timestamp="2023-06-30T07:10:08.937Z" skipped="0" failure-evaluating="0">
    <!-- 添加自定义属性设置执行名称和摘要 -->
    <properties>
      <property name="execution_name" value="自定义自动化测试执行(2023-06-30)"/>
      <property name="execution_summary" value="本次执行包含1个UI自动化用例,执行结果为失败,失败原因:元素未找到"/>
    </properties>
    <testcase name="test1" classname="testim.io.test" time="253.413" ownedBy="Staysure Automation" ownerEmail="automationteam@staysure.co.uk">
      <system-out>https://app.testim.io/#/project/9GScCUXVSOmXaUeDNvKA/branch/master/test/0gEraRql06D0MQdm?result-id=P2folrIsYwSNXOYr</system-out>
      <failure message="Step Failed: Element not found More info at: https://app.testim.io/#/project/9GScCU/branch/master/test/0gEraRql?result-id=P2folrIsY"/>
        <properties>
          <property name="test_key" value="SPT-4323" />
        </properties>
    </testcase>
  </testsuite>
</testsuites>

Xray会自动识别execution_name作为测试执行的名称,execution_summary作为执行的描述/摘要,该规则适用于Xray Cloud和Server版本的JUnit导入流程。

方法二:结合Xray REST API事后更新执行信息

如果无法修改JUnit XML,可在Jenkins流水线中先完成结果导入,再调用Xray API更新执行的名称和摘要:

  1. 调整流水线步骤,捕获导入后的执行ID,再发起API更新请求:
stage('Upload xray test results') {
    // 执行Xray导入并获取返回结果
    def importResult = step([$class: 'XrayImportBuilder', 
        endpointName: '/junit', 
        importFilePath: 'testim-tests-report2.xml', 
        importInParallel: 'false', 
        importToSameExecution: 'false', 
        projectKey: 'PSTT', 
        serverInstance: 'CLOUD-0ca', 
        testPlanKey: 'PSTT-3711'])
    
    // 从返回结果中提取测试执行的Key(格式如PSTT-XXXX)
    def executionKey = importResult.execution.key
    
    // 调用Xray API更新执行的名称和摘要
    httpRequest(
        url: "https://your-jira-domain/rest/raven/1.0/api/execution/${executionKey}",
        httpMode: 'PUT',
        contentType: 'APPLICATION_JSON',
        requestBody: '''{
            "fields": {
                "summary": "自定义自动化测试执行(2023-06-30)",
                "description": "本次执行包含1个UI自动化用例,执行结果为失败,失败原因:元素未找到"
            }
        }''',
        authentication: 'Jira-Xray-凭证' // 需要提前在Jenkins凭证中配置有权限的Jira账号
    )
}

注意:需要确保Jenkins安装了HTTP Request插件,并且配置的Jira凭证拥有修改Xray测试执行的权限。

内容的提问来源于stack exchange,提问作者Nipuna Madusanka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 18:03:11