From a548219c68de2eb201f3968fe32ddb9c6470db1b Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 5 Sep 2024 12:33:08 +0800 Subject: [PATCH 1/9] =?UTF-8?q?feat=EF=BC=9A=E6=BA=90=E6=9D=90=E6=96=99?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E4=BC=98=E5=8C=96=20#10733?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/pojo/PipelineBuildMaterial.kt | 6 +++++- .../devops/process/engine/dao/PipelineBuildDao.kt | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/PipelineBuildMaterial.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/PipelineBuildMaterial.kt index 4aa9a4cb288..e24e2d84c42 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/PipelineBuildMaterial.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/PipelineBuildMaterial.kt @@ -48,5 +48,9 @@ data class PipelineBuildMaterial( @get:Schema(title = "当前提交备注信息", required = false) val newCommitComment: String?, @get:Schema(title = "提交次数", required = false) - val commitTimes: Int? + val commitTimes: Int?, + @get:Schema(title = "是否为源材料主仓库", required = false) + val mainRepo: Boolean? = false, + @get:Schema(title = "提交时间", required = false) + val createTime: Long? = System.currentTimeMillis() / 1000 ) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt index 7fd58fb4ad4..32a28167339 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt @@ -1811,7 +1811,15 @@ class PipelineBuildDao { errorCode = t.errorCode, errorMsg = t.errorMsg, material = t.material?.let { - JsonUtil.getObjectMapper().readValue(it) as List + val list = JsonUtil.getObjectMapper().readValue(it) as List + list.sortedWith { o1, o2 -> + val (mainRepo1, createTime1) = (o1.mainRepo ?: false) to (o2.createTime ?: 0) + val (mainRepo2, createTime2) = (o1.mainRepo ?: false) to (o2.createTime ?: 0) + when { + mainRepo1 == mainRepo2 -> createTime2.compareTo(createTime1) + else -> mainRepo2.compareTo(mainRepo1) + } + } }, updateTime = t.updateTime.timestampmilli(), recommendVersion = t.recommendVersion, From e85b22a3d02f72dbf47fdbbd07784d26f84d6cb0 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 5 Sep 2024 15:32:30 +0800 Subject: [PATCH 2/9] =?UTF-8?q?feat=EF=BC=9A=E6=BA=90=E6=9D=90=E6=96=99?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E4=BC=98=E5=8C=96=20#10733?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tencent/devops/process/engine/dao/PipelineBuildDao.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt index 32a28167339..31148d21298 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt @@ -1813,8 +1813,8 @@ class PipelineBuildDao { material = t.material?.let { val list = JsonUtil.getObjectMapper().readValue(it) as List list.sortedWith { o1, o2 -> - val (mainRepo1, createTime1) = (o1.mainRepo ?: false) to (o2.createTime ?: 0) - val (mainRepo2, createTime2) = (o1.mainRepo ?: false) to (o2.createTime ?: 0) + val (mainRepo1, createTime1) = (o1.mainRepo ?: false) to (o1.createTime ?: 0) + val (mainRepo2, createTime2) = (o2.mainRepo ?: false) to (o2.createTime ?: 0) when { mainRepo1 == mainRepo2 -> createTime2.compareTo(createTime1) else -> mainRepo2.compareTo(mainRepo1) From 2dcd34d98b3d471f0b24fa8769d4592f2be3543e Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 5 Sep 2024 16:27:15 +0800 Subject: [PATCH 3/9] =?UTF-8?q?feat=EF=BC=9A=E6=BA=90=E6=9D=90=E6=96=99?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E4=BC=98=E5=8C=96=20#10733?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/engine/dao/PipelineBuildDao.kt | 10 +--------- .../engine/service/PipelineRuntimeService.kt | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt index 31148d21298..7fd58fb4ad4 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt @@ -1811,15 +1811,7 @@ class PipelineBuildDao { errorCode = t.errorCode, errorMsg = t.errorMsg, material = t.material?.let { - val list = JsonUtil.getObjectMapper().readValue(it) as List - list.sortedWith { o1, o2 -> - val (mainRepo1, createTime1) = (o1.mainRepo ?: false) to (o1.createTime ?: 0) - val (mainRepo2, createTime2) = (o2.mainRepo ?: false) to (o2.createTime ?: 0) - when { - mainRepo1 == mainRepo2 -> createTime2.compareTo(createTime1) - else -> mainRepo2.compareTo(mainRepo1) - } - } + JsonUtil.getObjectMapper().readValue(it) as List }, updateTime = t.updateTime.timestampmilli(), recommendVersion = t.recommendVersion, diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt index 678d1d370a7..991e165edab 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt @@ -478,7 +478,20 @@ class PipelineRuntimeService @Autowired constructor( status = status.name, stageStatus = stageStatus, currentTimestamp = currentTimestamp, - material = material?.sortedBy { it.aliasName }, + material = material?.let { list -> + list.sortedWith { o1, o2 -> + val (mainRepo1, createTime1) = (o1.mainRepo ?: false) to (o1.createTime ?: 0) + val (mainRepo2, createTime2) = (o2.mainRepo ?: false) to (o2.createTime ?: 0) + when { + mainRepo1 == mainRepo2 -> if (mainRepo1) { + createTime2.compareTo(createTime1) + } else { + (o1.aliasName ?: "").compareTo(o2.aliasName ?: "") + } + else -> mainRepo2.compareTo(mainRepo1) + } + } + }, queueTime = queueTime, artifactList = artifactList, remark = remark, From f60e04ac11144bf1fac870142996624e9627a9d6 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 6 Sep 2024 10:34:35 +0800 Subject: [PATCH 4/9] =?UTF-8?q?feat=EF=BC=9A=E6=BA=90=E6=9D=90=E6=96=99?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E4=BC=98=E5=8C=96=20#10733?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builds/BuildRepositoryMaterialResource.kt | 6 +++- .../process/pojo/PipelineBuildMaterial.kt | 4 ++- .../service/PipelineBuildMaterialService.kt | 35 +++++++++++++------ .../BuildRepositoryMaterialResourceImpl.kt | 6 ++-- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/builds/BuildRepositoryMaterialResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/builds/BuildRepositoryMaterialResource.kt index b7d922614e5..161174dc10c 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/builds/BuildRepositoryMaterialResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/builds/BuildRepositoryMaterialResource.kt @@ -28,6 +28,7 @@ package com.tencent.devops.process.api.builds import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_BUILD_ID +import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_CI_TASK_ID import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_PIPELINE_ID import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_PROJECT_ID import com.tencent.devops.common.api.pojo.Result @@ -61,6 +62,9 @@ interface BuildRepositoryMaterialResource { @HeaderParam(AUTH_HEADER_DEVOPS_PIPELINE_ID) pipelineId: String, @Parameter(description = "物料列表", required = true) - pipelineBuildMaterials: List + pipelineBuildMaterials: List, + @Parameter(description = "插件ID", required = true) + @HeaderParam(AUTH_HEADER_DEVOPS_CI_TASK_ID) + taskId: String? ): Result } diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/PipelineBuildMaterial.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/PipelineBuildMaterial.kt index e24e2d84c42..5227e0bdd0a 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/PipelineBuildMaterial.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/PipelineBuildMaterial.kt @@ -52,5 +52,7 @@ data class PipelineBuildMaterial( @get:Schema(title = "是否为源材料主仓库", required = false) val mainRepo: Boolean? = false, @get:Schema(title = "提交时间", required = false) - val createTime: Long? = System.currentTimeMillis() / 1000 + val createTime: Long? = System.currentTimeMillis() / 1000, + @get:Schema(title = "插件ID", required = false) + val taskId: String? = null ) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt index 5e72733df65..c115b467efc 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt @@ -45,23 +45,38 @@ class PipelineBuildMaterialService @Autowired constructor( fun saveBuildMaterial( buildId: String, projectId: String, - pipelineBuildMaterials: List + pipelineBuildMaterials: List, + taskId: String? ): Int { - var newPipelineBuildMaterials = pipelineBuildMaterials - val pipelineBuildHistoryRecord = pipelineBuildDao.getBuildInfo(dslContext, projectId, buildId) + val materialList = mutableListOf() + val pipelineBuildHistoryRecord = pipelineBuildDao.getBuildInfo(dslContext, projectId, buildId) ?: return 0 // 如果找不到构建历史或重试时,不做原材料写入 - if (pipelineBuildHistoryRecord == null || - pipelineBuildHistoryRecord.executeCount?.let { it > 1 } == true - ) { + logger.info("save build material|buildId=$buildId|taskId=$taskId|${pipelineBuildMaterials.size}") + val material = pipelineBuildHistoryRecord.material + // 重试操作,如果源材料为空且第一次执行的源材料包含空TaskId,则不保存,否则会出现重复数据 + val containsEmptyTaskId = material?.find { it.taskId.isNullOrBlank() } != null || taskId.isNullOrBlank() + if (pipelineBuildHistoryRecord.executeCount?.let { it > 1 } == true && containsEmptyTaskId) { + logger.info("skip save build material") return 0 } - val material = pipelineBuildHistoryRecord.material + val existTaskIds = material?.mapNotNull { it.taskId } ?: listOf() if (!material.isNullOrEmpty()) { - newPipelineBuildMaterials = newPipelineBuildMaterials.plus(material) + materialList.addAll(material) + // 不包含空taskId,则需要过滤掉空taskId + if (!containsEmptyTaskId) { + pipelineBuildMaterials.forEach { + if (!existTaskIds.contains(taskId)) { + materialList.add(it.copy(taskId = taskId)) + } + } + } else { + materialList.addAll(pipelineBuildMaterials.map { it.copy(taskId = taskId) }) + } + } else { + materialList.addAll(pipelineBuildMaterials.map { it.copy(taskId = taskId) }) } - val materials = JsonUtil.toJson(newPipelineBuildMaterials, formatted = false) - logger.info("BuildId: $buildId save material size: ${newPipelineBuildMaterials.size}") + val materials = JsonUtil.toJson(materialList, formatted = false) pipelineBuildDao.updateBuildMaterial( dslContext = dslContext, projectId = projectId, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/builds/BuildRepositoryMaterialResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/builds/BuildRepositoryMaterialResourceImpl.kt index 37cb878f97c..87022719546 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/builds/BuildRepositoryMaterialResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/builds/BuildRepositoryMaterialResourceImpl.kt @@ -44,13 +44,15 @@ class BuildRepositoryMaterialResourceImpl @Autowired constructor( buildId: String, projectId: String, pipelineId: String, - pipelineBuildMaterials: List + pipelineBuildMaterials: List, + taskId: String? ): Result { checkParam(buildId = buildId, projectId = projectId, pipelineId = pipelineId) return Result(pipelineBuildMaterialService.saveBuildMaterial( buildId = buildId, projectId = projectId, - pipelineBuildMaterials = pipelineBuildMaterials + pipelineBuildMaterials = pipelineBuildMaterials, + taskId = taskId )) } From 13013be190cfc74981741453bd4762ce37c29a9d Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 12 Sep 2024 15:49:32 +0800 Subject: [PATCH 5/9] =?UTF-8?q?feat=EF=BC=9A=E6=BA=90=E6=9D=90=E6=96=99?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E4=BC=98=E5=8C=96=20#10733?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/service/PipelineBuildMaterialService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt index c115b467efc..abaa37c1c7b 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt @@ -53,7 +53,7 @@ class PipelineBuildMaterialService @Autowired constructor( // 如果找不到构建历史或重试时,不做原材料写入 logger.info("save build material|buildId=$buildId|taskId=$taskId|${pipelineBuildMaterials.size}") val material = pipelineBuildHistoryRecord.material - // 重试操作,如果源材料为空且第一次执行的源材料包含空TaskId,则不保存,否则会出现重复数据 + // 重试操作,如果源材料包含空TaskId,则不保存,否则会出现重复数据 val containsEmptyTaskId = material?.find { it.taskId.isNullOrBlank() } != null || taskId.isNullOrBlank() if (pipelineBuildHistoryRecord.executeCount?.let { it > 1 } == true && containsEmptyTaskId) { logger.info("skip save build material") From 30d8e6ef5fccaa6bd89ba5e19664dc90ac1d9ccb Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 12 Sep 2024 16:40:09 +0800 Subject: [PATCH 6/9] =?UTF-8?q?feat=EF=BC=9A=E6=BA=90=E6=9D=90=E6=96=99?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E4=BC=98=E5=8C=96=20#10733?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/service/PipelineBuildMaterialService.kt | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt index abaa37c1c7b..c14b8191336 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt @@ -53,7 +53,7 @@ class PipelineBuildMaterialService @Autowired constructor( // 如果找不到构建历史或重试时,不做原材料写入 logger.info("save build material|buildId=$buildId|taskId=$taskId|${pipelineBuildMaterials.size}") val material = pipelineBuildHistoryRecord.material - // 重试操作,如果源材料包含空TaskId,则不保存,否则会出现重复数据 + // 重试场景下,只要有空taskId,就直接返回 val containsEmptyTaskId = material?.find { it.taskId.isNullOrBlank() } != null || taskId.isNullOrBlank() if (pipelineBuildHistoryRecord.executeCount?.let { it > 1 } == true && containsEmptyTaskId) { logger.info("skip save build material") @@ -62,14 +62,8 @@ class PipelineBuildMaterialService @Autowired constructor( val existTaskIds = material?.mapNotNull { it.taskId } ?: listOf() if (!material.isNullOrEmpty()) { materialList.addAll(material) - // 不包含空taskId,则需要过滤掉空taskId - if (!containsEmptyTaskId) { - pipelineBuildMaterials.forEach { - if (!existTaskIds.contains(taskId)) { - materialList.add(it.copy(taskId = taskId)) - } - } - } else { + // 不包含空taskId,没有task + if ((!containsEmptyTaskId && !existTaskIds.contains(taskId)) || containsEmptyTaskId) { materialList.addAll(pipelineBuildMaterials.map { it.copy(taskId = taskId) }) } } else { From 3f969044ebf993c84e0d56082aea1d9e6a361079 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 12 Sep 2024 18:06:21 +0800 Subject: [PATCH 7/9] =?UTF-8?q?feat=EF=BC=9A=E6=BA=90=E6=9D=90=E6=96=99?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E4=BC=98=E5=8C=96=20#10733?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/service/PipelineBuildMaterialService.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt index c14b8191336..f31f2d0eea2 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt @@ -62,7 +62,8 @@ class PipelineBuildMaterialService @Autowired constructor( val existTaskIds = material?.mapNotNull { it.taskId } ?: listOf() if (!material.isNullOrEmpty()) { materialList.addAll(material) - // 不包含空taskId,没有task + // 存在空TaskId,直接添加 + // 不存在空TaskId,旧数据不存在当前TaskId上报的源材料时则添加 if ((!containsEmptyTaskId && !existTaskIds.contains(taskId)) || containsEmptyTaskId) { materialList.addAll(pipelineBuildMaterials.map { it.copy(taskId = taskId) }) } From bf5b304baaa4bd806c5468786c27b825cbcfe0dd Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 13 Sep 2024 17:47:55 +0800 Subject: [PATCH 8/9] =?UTF-8?q?feat=EF=BC=9A=E6=BA=90=E6=9D=90=E6=96=99?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E4=BC=98=E5=8C=96=20#10733?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/service/PipelineRuntimeService.kt | 15 +------------- .../service/PipelineBuildMaterialService.kt | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt index 991e165edab..9b5a266ea19 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt @@ -478,20 +478,7 @@ class PipelineRuntimeService @Autowired constructor( status = status.name, stageStatus = stageStatus, currentTimestamp = currentTimestamp, - material = material?.let { list -> - list.sortedWith { o1, o2 -> - val (mainRepo1, createTime1) = (o1.mainRepo ?: false) to (o1.createTime ?: 0) - val (mainRepo2, createTime2) = (o2.mainRepo ?: false) to (o2.createTime ?: 0) - when { - mainRepo1 == mainRepo2 -> if (mainRepo1) { - createTime2.compareTo(createTime1) - } else { - (o1.aliasName ?: "").compareTo(o2.aliasName ?: "") - } - else -> mainRepo2.compareTo(mainRepo1) - } - } - }, + material = material, queueTime = queueTime, artifactList = artifactList, remark = remark, diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt index f31f2d0eea2..f3fb5fcdc19 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt @@ -42,6 +42,7 @@ class PipelineBuildMaterialService @Autowired constructor( ) { private val logger = LoggerFactory.getLogger(PipelineBuildMaterialService::class.java) + @SuppressWarnings("CyclomaticComplexMethod") fun saveBuildMaterial( buildId: String, projectId: String, @@ -70,8 +71,25 @@ class PipelineBuildMaterialService @Autowired constructor( } else { materialList.addAll(pipelineBuildMaterials.map { it.copy(taskId = taskId) }) } + // 按顺序保存 + val materials = JsonUtil.toJson( + bean = materialList.let { list -> + list.sortedWith { o1, o2 -> + val (mainRepo1, createTime1) = (o1.mainRepo ?: false) to (o1.createTime ?: 0) + val (mainRepo2, createTime2) = (o2.mainRepo ?: false) to (o2.createTime ?: 0) + when { + mainRepo1 == mainRepo2 -> if (mainRepo1) { + createTime2.compareTo(createTime1) + } else { + (o1.aliasName ?: "").compareTo(o2.aliasName ?: "") + } - val materials = JsonUtil.toJson(materialList, formatted = false) + else -> mainRepo2.compareTo(mainRepo1) + } + } + }, + formatted = false + ) pipelineBuildDao.updateBuildMaterial( dslContext = dslContext, projectId = projectId, From b346f169bf18bf0f52a53fa5ea45c2fd8efec568 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Sat, 14 Sep 2024 11:34:40 +0800 Subject: [PATCH 9/9] =?UTF-8?q?feat=EF=BC=9A=E6=BA=90=E6=9D=90=E6=96=99?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E4=BC=98=E5=8C=96=20#10733?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/service/PipelineBuildMaterialService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt index f3fb5fcdc19..80cef9e34f2 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineBuildMaterialService.kt @@ -42,7 +42,7 @@ class PipelineBuildMaterialService @Autowired constructor( ) { private val logger = LoggerFactory.getLogger(PipelineBuildMaterialService::class.java) - @SuppressWarnings("CyclomaticComplexMethod") + @SuppressWarnings("CyclomaticComplexMethod", "ComplexMethod") fun saveBuildMaterial( buildId: String, projectId: String,