Skip to content

Commit

Permalink
fix: 修复执行测试计划后报告type没有区分的问题
Browse files Browse the repository at this point in the history
--bug=1045529 --user=刘瑞斌 jenkins执行计划组-打开报告链接没子计划详情 https://www.tapd.cn/55049933/s/1566646
  • Loading branch information
liuruibin committed Aug 21, 2024
1 parent 1e19c11 commit 5773c6f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/io/metersphere/v3/MeterSphereBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnul
run.setResult(Result.FAILURE);
return;
}
result = MeterSphereUtils.runTestPlan(run, client, first.get().getId(), realProjectId, msEndpoint);
result = MeterSphereUtils.runTestPlan(run, client, first.get(), organizationId, realProjectId, msEndpoint);
// 使用case的结果
run.setResult(result ? Result.SUCCESS : Result.FAILURE);
} catch (Exception e) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/metersphere/v3/commons/model/TestPlanDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class TestPlanDTO {

private String tags;

private String type;

private static final long serialVersionUID = 1L;

public String getProjectName() {
Expand Down Expand Up @@ -162,4 +164,12 @@ public String getNum() {
public void setNum(String num) {
this.num = num;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import hudson.model.Run;
import io.metersphere.v3.client.MeterSphereClient;
import io.metersphere.v3.commons.constants.Results;
import io.metersphere.v3.commons.model.TestPlanDTO;
import org.apache.commons.lang.StringUtils;

import java.io.PrintStream;
Expand All @@ -18,13 +19,16 @@ private static void log(String msg) {
}


public static boolean runTestPlan(Run<?, ?> run, MeterSphereClient meterSphereClient, String testPlanId, String projectId, String endpoint) throws InterruptedException {
public static boolean runTestPlan(Run<?, ?> run, MeterSphereClient meterSphereClient, TestPlanDTO testPlan, String organizationId, String projectId, String endpoint) throws InterruptedException {
log("测试计划开始执行");
String id = meterSphereClient.exeTestPlan(testPlanId);
log("生成测试报告id: " + id);
String id = meterSphereClient.exeTestPlan(testPlan.getId());
log("生成测试报告id: " + id + ",测试计划: " + testPlan.getName() + ",类型: " + testPlan.getType());
boolean flag = true;
boolean state = true;
while (state) {
// 避免报告还没入库
Thread.sleep(5000);

String status = meterSphereClient.getStatus(id);
if (Results.STOPPED.equalsIgnoreCase(status)) {
flag = false;
Expand All @@ -41,21 +45,19 @@ public static boolean runTestPlan(Run<?, ?> run, MeterSphereClient meterSphereCl
state = false;
log("该测试计划已完成");
}
Thread.sleep(5000);
}

String openMode = "anon";
if (!meterSphereClient.checkLicense()) {
openMode = "auth";
}

String reportView = "/#/test-plan/testPlanReportDetail?id=" + id + "&type=TEST_PLAN";
String reportView = String.format("/#/test-plan/testPlanReportDetail?id=%s&type=%s&pId=%s&orgId=%s", id, testPlan.getType(), projectId, organizationId);
if (StringUtils.equals(openMode, "anon")) {
Map<String, String> params = new HashMap<>();
params.put("projectId", projectId);
params.put("reportId", id);
String shareUrl = meterSphereClient.getShareInfo(params);
reportView = "/#/share/shareReportTestPlan" + shareUrl;
reportView = String.format("/#/share/shareReportTestPlan%s&type=%s&pId=%s&orgId=%s", shareUrl, testPlan.getType(), projectId, organizationId);
}
log("点击链接进入测试计划报告页面:" + StringUtils.stripEnd(endpoint, "/") + reportView);
return flag;
Expand Down

0 comments on commit 5773c6f

Please sign in to comment.