From d8d30dbfe3b53fd1b5c3a4fe065fb1a501312510 Mon Sep 17 00:00:00 2001 From: royalhuang Date: Fri, 20 Aug 2021 15:26:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20stage=E6=94=AF=E6=8C=81=E8=B4=A8?= =?UTF-8?q?=E9=87=8F=E7=BA=A2=E7=BA=BF=E7=9A=84=E5=87=86=E5=85=A5=E5=87=86?= =?UTF-8?q?=E5=87=BA=20#4732?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/engine/pojo/PipelineBuildStage.kt | 15 +---------- .../engine/dao/PipelineBuildStageDao.kt | 18 ------------- .../engine/service/PipelineStageService.kt | 17 ++---------- .../stage/impl/StartContainerStageCmd.kt | 26 ++++++------------- 4 files changed, 11 insertions(+), 65 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/engine/pojo/PipelineBuildStage.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/engine/pojo/PipelineBuildStage.kt index 847c3bfc453..3ea284e3b4a 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/engine/pojo/PipelineBuildStage.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/engine/pojo/PipelineBuildStage.kt @@ -45,17 +45,4 @@ data class PipelineBuildStage( val controlOption: PipelineBuildStageControlOption?, var checkIn: StagePauseCheck? = null, var checkOut: StagePauseCheck? = null -) { - - /** - * 判断是否已经被质量红线拦截,仅用于 finally 前序 stage 判断,其他地方请勿使用 - */ - fun checkQualityFailed(): Boolean { - return if (checkIn?.status == BuildStatus.QUALITY_CHECK_FAIL.name || - checkOut?.status == BuildStatus.QUALITY_CHECK_FAIL.name) { - // #4732 如果判断是已拦截的状态,则忽略原状态,将 stage 状态刷新为 QUALITY_CHECK_FAIL - status = BuildStatus.QUALITY_CHECK_FAIL - true - } else false - } -} +) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildStageDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildStageDao.kt index df9d403d598..06c3571a98f 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildStageDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildStageDao.kt @@ -260,24 +260,6 @@ class PipelineBuildStageDao { } } - fun updateOptions( - dslContext: DSLContext, - buildId: String, - stageId: String, - controlOption: PipelineBuildStageControlOption?, - checkIn: StagePauseCheck? = null, - checkOut: StagePauseCheck? = null - ): Int { - return with(T_PIPELINE_BUILD_STAGE) { - val option = if (controlOption != null) JsonUtil.toJson(controlOption) else null - val update = dslContext.update(this) - .set(CONDITIONS, option) - if (checkIn != null) update.set(CHECK_IN, JsonUtil.toJson(checkIn)) - if (checkOut != null) update.set(CHECK_OUT, JsonUtil.toJson(checkOut)) - update.where(BUILD_ID.eq(buildId)).and(STAGE_ID.eq(stageId)).execute() - } - } - fun update( dslContext: DSLContext, buildId: String, diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineStageService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineStageService.kt index 2480880e984..30e877f0c7d 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineStageService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineStageService.kt @@ -110,20 +110,6 @@ class PipelineStageService @Autowired constructor( ) } - fun updateStageOptions( - buildId: String, - stageId: String, - stage: PipelineBuildStage - ) { - logger.info("[$buildId]|updateStageOptions|stageId=$stageId|controlOption=${stage.controlOption}" + - "|checkIn=${stage.checkIn}|checkOut=${stage.checkOut}") - pipelineBuildStageDao.updateOptions( - dslContext = dslContext, buildId = buildId, - stageId = stageId, controlOption = stage.controlOption, - checkIn = stage.checkIn, checkOut = stage.checkOut - ) - } - fun listStages(buildId: String): List { val list = pipelineBuildStageDao.listByBuildId(dslContext, buildId) val result = mutableListOf() @@ -170,9 +156,10 @@ class PipelineStageService @Autowired constructor( ) dslContext.transaction { configuration -> val context = DSL.using(configuration) - pipelineBuildStageDao.updateOptions( + pipelineBuildStageDao.updateStatus( dslContext = context, buildId = buildId, stageId = stageId, controlOption = controlOption!!, + buildStatus = BuildStatus.QUALITY_CHECK_FAIL, checkIn = checkIn, checkOut = checkOut ) pipelineBuildDao.updateBuildStageStatus( diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/stage/impl/StartContainerStageCmd.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/stage/impl/StartContainerStageCmd.kt index 50bbecf2f14..0ba7d51df77 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/stage/impl/StartContainerStageCmd.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/stage/impl/StartContainerStageCmd.kt @@ -94,11 +94,6 @@ class StartContainerStageCmd( if (stageStatus.isFinish() || stageStatus == BuildStatus.STAGE_SUCCESS) { commandContext.buildStatus = stageStatus // 已经是结束或者是STAGE_SUCCESS就直接返回 } else { - // 查找最后一个结束状态的Stage (排除Finally) - if (commandContext.stage.controlOption?.finally == true) { - commandContext.previousStageStatus = fetchPreviousStageStatus(commandContext) - } - stageStatus = pickJob(commandContext, actionType = newActionType, userId = event.userId) if (commandContext.skipContainerNum == commandContext.containers.size) { @@ -137,6 +132,14 @@ class StartContainerStageCmd( var fail: BuildStatus? = null var cancel: BuildStatus? = null + // 查找最后一个结束状态的Stage (排除Finally) + if (commandContext.stage.controlOption?.finally == true) { + commandContext.previousStageStatus = pipelineStageService.listStages(commandContext.stage.buildId) + .lastOrNull { + it.stageId != commandContext.stage.stageId && + (it.status.isFinish() || it.status == BuildStatus.STAGE_SUCCESS) + }?.status + } // 同一Stage下的多个Container是并行 commandContext.containers.forEach { container -> if (container.status.isCancel()) { @@ -163,19 +166,6 @@ class StartContainerStageCmd( return running ?: fail ?: cancel ?: BuildStatus.SUCCEED } - /** - * 获取前序已完成的stage状态 - * 如果前序stageStatus是完成状态或[BuildStatus.STAGE_SUCCESS]则直接取用 - * 如果前序stage是因为质量红线准入准出而被直接终止,则取用[BuildStatus.QUALITY_CHECK_FAIL] - */ - private fun fetchPreviousStageStatus(commandContext: StageContext): BuildStatus? { - return pipelineStageService.listStages(commandContext.stage.buildId) - .lastOrNull { - it.stageId != commandContext.stage.stageId && - (it.status.isFinish() || it.status == BuildStatus.STAGE_SUCCESS || it.checkQualityFailed()) - }?.status - } - private fun sendBuildContainerEvent( commandContext: StageContext, container: PipelineBuildContainer,