增加同步锁
This commit is contained in:
parent
20670df44c
commit
0ccb068bfd
@ -509,23 +509,14 @@ public class JenkinsServiceIntegrationImpl extends BaseExternalSystemIntegration
|
||||
@Override
|
||||
public JenkinsBuildResponse getBuildDetails(ExternalSystem externalSystem, String jobName, Integer buildNumber) {
|
||||
try {
|
||||
// 构建 tree 参数,只获取我们需要的字段
|
||||
String treeQuery = "number,url,result,duration,timestamp,building," +
|
||||
// 变更集字段更精确:author.fullName 与 msg
|
||||
"changeSets[kind,items[commitId,author[fullName],msg,timestamp,affectedPaths]]," +
|
||||
// 制品
|
||||
"artifacts[fileName,relativePath,displayPath]," +
|
||||
// Git 插件 BuildData,兜底的 commit 信息
|
||||
"actions[_class,lastBuiltRevision[SHA1,branch[name,SHA1]]]";
|
||||
|
||||
// 直接使用原始系统信息构建URL(URL不需要解密)
|
||||
// 不使用 tree 参数,直接获取完整的 build 详情(与老项目保持一致)
|
||||
// 原因:使用 tree 参数时,如果构建没有代码变更,Jenkins 不会返回 changeSets 字段
|
||||
String url = UriComponentsBuilder.fromHttpUrl(externalSystem.getUrl())
|
||||
.path("/job/")
|
||||
.path(jobName)
|
||||
.path("/")
|
||||
.path(buildNumber.toString())
|
||||
.path("/api/json")
|
||||
.queryParam("tree", treeQuery)
|
||||
.build()
|
||||
.toUriString();
|
||||
|
||||
@ -563,18 +554,19 @@ public class JenkinsServiceIntegrationImpl extends BaseExternalSystemIntegration
|
||||
}
|
||||
}
|
||||
|
||||
// 提取 gitCommitId:优先 changeSets.items[0].commitId,兜底 actions.BuildData.lastBuiltRevision.SHA1
|
||||
// 提取 gitCommitId:优先 changeSet/changeSets,兜底 actions.BuildData.lastBuiltRevision.SHA1
|
||||
String commitId = null;
|
||||
try {
|
||||
// 先尝试从 changeSets 拿
|
||||
if (buildResponse.getChangeSets() != null && !buildResponse.getChangeSets().isEmpty()) {
|
||||
var first = buildResponse.getChangeSets().get(0);
|
||||
if (first.getItems() != null && !first.getItems().isEmpty()) {
|
||||
commitId = first.getItems().get(0).getCommitId();
|
||||
}
|
||||
// 1. 先尝试从 changeSet(单数,FreeStyle 任务)获取
|
||||
if (buildResponse.getChangeSet() != null &&
|
||||
buildResponse.getChangeSet().getItems() != null &&
|
||||
!buildResponse.getChangeSet().getItems().isEmpty()) {
|
||||
// 取最后一个 commit(最新的)
|
||||
var items = buildResponse.getChangeSet().getItems();
|
||||
commitId = items.get(items.size() - 1).getCommitId();
|
||||
}
|
||||
// 2. 兜底:解析原始 JSON 的 actions 查找 BuildData
|
||||
if (commitId == null) {
|
||||
// 兜底:解析原始 JSON 的 actions 查找 BuildData
|
||||
com.fasterxml.jackson.databind.JsonNode root = mapper.readTree(response.getBody());
|
||||
com.fasterxml.jackson.databind.JsonNode actions = root.get("actions");
|
||||
if (actions != null && actions.isArray()) {
|
||||
|
||||
@ -104,9 +104,9 @@ public class JenkinsBuildResponse {
|
||||
private List<BuildParameter> actions;
|
||||
|
||||
/**
|
||||
* 构建变更集
|
||||
* 构建变更集(Jenkins FreeStyle 任务返回 changeSet 单数形式)
|
||||
*/
|
||||
private List<ChangeSet> changeSets;
|
||||
private ChangeSet changeSet;
|
||||
|
||||
/**
|
||||
* 构建制品
|
||||
@ -154,12 +154,23 @@ public class JenkinsBuildResponse {
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class ChangeSetItem {
|
||||
private String commitId;
|
||||
private String author;
|
||||
private Author author; // Jenkins 返回的是对象,不是字符串
|
||||
private String authorEmail;
|
||||
private String msg;
|
||||
private String comment;
|
||||
private Long timestamp;
|
||||
private String date;
|
||||
private String id;
|
||||
private List<String> affectedPaths;
|
||||
}
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class Author {
|
||||
private String absoluteUrl;
|
||||
private String fullName;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Artifact {
|
||||
private String displayPath;
|
||||
|
||||
@ -332,10 +332,10 @@ public class JenkinsBuildServiceImpl extends BaseServiceImpl<JenkinsBuild, Jenki
|
||||
}
|
||||
|
||||
try {
|
||||
// 保存 actions 和 changeSets 到 JSON
|
||||
// 保存 actions 和 changeSet 到 JSON
|
||||
Map<String, Object> buildData = new HashMap<>();
|
||||
buildData.put("actions", response.getActions());
|
||||
buildData.put("changeSets", response.getChangeSets());
|
||||
buildData.put("changeSet", response.getChangeSet());
|
||||
buildData.put("gitCommitId", response.getGitCommitId());
|
||||
String actionsJson = objectMapper.writeValueAsString(buildData);
|
||||
jenkinsBuild.setActions(actionsJson);
|
||||
|
||||
@ -91,9 +91,10 @@ public class JenkinsBuildDelegate extends BaseNodeDelegate<JenkinsBuildInputMapp
|
||||
JenkinsBuildResponse buildDetails = jenkinsServiceIntegration.getBuildDetails(externalSystem, jobName, buildInfo.getBuildNumber());
|
||||
|
||||
// 打印调试信息(仅数量,避免大对象噪音)
|
||||
int changeSetsCount = (buildDetails.getChangeSets() != null) ? buildDetails.getChangeSets().size() : 0;
|
||||
int changeSetItemsCount = (buildDetails.getChangeSet() != null && buildDetails.getChangeSet().getItems() != null)
|
||||
? buildDetails.getChangeSet().getItems().size() : 0;
|
||||
int artifactsCount = (buildDetails.getArtifacts() != null) ? buildDetails.getArtifacts().size() : 0;
|
||||
log.info("Build details - changeSetsCount={}, artifactsCount={}", changeSetsCount, artifactsCount);
|
||||
log.info("Build details - changeSetItemsCount={}, artifactsCount={}", changeSetItemsCount, artifactsCount);
|
||||
|
||||
// 7. 设置输出结果(包含节点状态)
|
||||
fillOutputsFrom(buildInfo, buildDetails, buildStatus, output);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user