Skip to content

Commit

Permalink
feat: stage支持质量红线的准入准出 TencentBlueKing#4732 降低代码复杂度
Browse files Browse the repository at this point in the history
  • Loading branch information
royalhuang committed Aug 20, 2021
1 parent 17ddb5c commit df064e3
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ 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) {
Expand Down Expand Up @@ -132,14 +137,6 @@ 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 || it.checkQualityFailed())
}?.status
}
// 同一Stage下的多个Container是并行
commandContext.containers.forEach { container ->
if (container.status.isCancel()) {
Expand All @@ -166,6 +163,19 @@ 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,
Expand Down

0 comments on commit df064e3

Please sign in to comment.