From ebf90c0b228cdac683403bb4a844d0dca76c294e Mon Sep 17 00:00:00 2001 From: royalhuang Date: Thu, 28 Apr 2022 20:10:17 +0800 Subject: [PATCH] =?UTF-8?q?bug:=20=E4=BF=AE=E5=A4=8D=E9=87=8D=E8=AF=95?= =?UTF-8?q?=E5=92=8C=E4=BB=BB=E5=8A=A1=E8=AE=A4=E9=A2=86=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=9A=84=E9=80=BB=E8=BE=91=E9=97=AE=E9=A2=98=20#6646?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/api/service/ServiceVarResource.kt | 3 +++ .../process/service/PipelineContextService.kt | 14 ++++++++++++-- .../process/api/service/ServiceVarResourceImpl.kt | 9 +++++++-- .../trigger/listener/components/SendNotify.kt | 9 ++++++--- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceVarResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceVarResource.kt index 84bfff38c7d..4fd02166ff0 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceVarResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceVarResource.kt @@ -66,6 +66,9 @@ interface ServiceVarResource { @ApiParam(value = "项目ID", required = true) @QueryParam("projectId") projectId: String, + @ApiParam(value = "流水线ID", required = true) + @QueryParam("pipelineId") + pipelineId: String, @ApiParam(value = "构建ID", required = true) @QueryParam("buildId") buildId: String, diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineContextService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineContextService.kt index 63a88e0f569..abe2248087c 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineContextService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/PipelineContextService.kt @@ -39,6 +39,7 @@ import com.tencent.devops.common.pipeline.pojo.element.Element import com.tencent.devops.common.pipeline.type.BuildType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_EVENT import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_TIME_TRIGGER_KIND +import com.tencent.devops.process.bean.PipelineUrlBean import com.tencent.devops.process.engine.control.ControlUtils import com.tencent.devops.process.engine.service.PipelineBuildDetailService import com.tencent.devops.process.utils.PIPELINE_START_TYPE @@ -50,7 +51,8 @@ import org.springframework.stereotype.Service @Suppress("ComplexMethod", "TooManyFunctions", "NestedBlockDepth", "LongParameterList") @Service class PipelineContextService @Autowired constructor( - private val pipelineBuildDetailService: PipelineBuildDetailService + private val pipelineBuildDetailService: PipelineBuildDetailService, + private val pipelineUrlBean: PipelineUrlBean ) { private val logger = LoggerFactory.getLogger(PipelineContextService::class.java) @@ -119,8 +121,9 @@ class PipelineContextService @Autowired constructor( return contextMap } - fun buildContextToNotice( + fun buildFinishContext( projectId: String, + pipelineId: String, buildId: String ): Map { val modelDetail = pipelineBuildDetailService.get(projectId, buildId) ?: return emptyMap() @@ -152,6 +155,13 @@ class PipelineContextService @Autowired constructor( } contextMap["ci.build_status"] = previousStageStatus.name contextMap["ci.build_fail_tasknames"] = failTaskNameList.joinToString(",") + contextMap["ci.build_url"] = pipelineUrlBean.genBuildDetailUrl( + projectCode = projectId, + pipelineId = pipelineId, + buildId = buildId, + position = null, + stageId = null + ) } catch (ignore: Throwable) { logger.warn("BKSystemErrorMonitor|buildContextToNoticeFailed|", ignore) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceVarResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceVarResourceImpl.kt index 40df3e46e95..300d9c971cd 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceVarResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceVarResourceImpl.kt @@ -47,12 +47,17 @@ class ServiceVarResourceImpl @Autowired constructor( } } - override fun getContextVar(projectId: String, buildId: String, contextName: String?): Result> { + override fun getContextVar( + projectId: String, + pipelineId: String, + buildId: String, + contextName: String? + ): Result> { val buildVars = buildVariableService.getAllVariable(projectId, buildId) return if (contextName.isNullOrBlank()) { val contextVar = pipelineContextService.getAllBuildContext(buildVars).toMutableMap() Result( - contextVar.plus(pipelineContextService.buildContextToNotice(projectId, buildId)) + contextVar.plus(pipelineContextService.buildFinishContext(projectId, pipelineId, buildId)) ) } else { val context = pipelineContextService.getBuildContext(buildVars, contextName) diff --git a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/listener/components/SendNotify.kt b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/listener/components/SendNotify.kt index 8ef9a7d5537..a58a0c5c53d 100644 --- a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/listener/components/SendNotify.kt +++ b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/listener/components/SendNotify.kt @@ -89,9 +89,12 @@ class SendNotify @Autowired constructor( private fun sendNotifyV2(action: BaseAction, build: BuildHistory) { // 获取需要进行替换的variables val finishData = action.data.context.finishData!! - val projectId = finishData.projectId - val variables = client.get(ServiceVarResource::class) - .getContextVar(projectId = projectId, buildId = build.id, contextName = null).data + val variables = client.get(ServiceVarResource::class).getContextVar( + projectId = finishData.projectId, + pipelineId = finishData.pipelineId, + buildId = build.id, + contextName = null + ).data val notices = YamlUtil.getObjectMapper().readValue( finishData.normalizedYaml, ScriptBuildYaml::class.java ).notices