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 8, 2021
1 parent c3734e4 commit e1d1de9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,23 @@ 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 update = dslContext.update(this)
.set(CONDITIONS, JsonUtil.toJson(controlOption))
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.tencent.devops.common.pipeline.pojo.StageReviewRequest
import com.tencent.devops.common.websocket.enum.RefreshType
import com.tencent.devops.process.engine.common.BS_MANUAL_START_STAGE
import com.tencent.devops.process.engine.common.BS_STAGE_CANCELED_END_SOURCE
import com.tencent.devops.process.engine.common.BS_STAGE_QUALITY_CHECK_FAIL_END_SOURCE
import com.tencent.devops.process.engine.dao.PipelineBuildDao
import com.tencent.devops.process.engine.dao.PipelineBuildStageDao
import com.tencent.devops.process.engine.dao.PipelineBuildSummaryDao
Expand Down Expand Up @@ -137,6 +136,29 @@ class PipelineStageService @Autowired constructor(
}
}

fun checkQualityFailStage(userId: String, buildStage: PipelineBuildStage) {
with(buildStage) {
val allStageStatus = stageBuildDetailService.stageCheckQualityFail(buildId = buildId, stageId = stageId)
dslContext.transaction { configuration ->
val context = DSL.using(configuration)
pipelineBuildStageDao.updateOptions(
dslContext = context, buildId = buildId,
stageId = stageId, controlOption = controlOption!!,
checkIn = checkIn, checkOut = checkOut
)
pipelineBuildDao.updateBuildStageStatus(
dslContext = context, buildId = buildId, stageStatus = allStageStatus
)
}
pipelineEventDispatcher.dispatch(
PipelineBuildWebSocketPushEvent(
source = "checkQualityFailStage", projectId = projectId, pipelineId = pipelineId,
userId = userId, buildId = buildId, refreshTypes = RefreshType.HISTORY.binary
)
)
}
}

fun pauseStage(userId: String, buildStage: PipelineBuildStage) {
with(buildStage) {
// TODO 暂时只处理准入逻辑,后续和checkOut保持逻辑一致
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ class StageBuildDetailService(
controlOption: PipelineBuildStageControlOption,
checkIn: StagePauseCheck?,
checkOut: StagePauseCheck?
) {
): List<BuildStageStatus> {
logger.info("[$buildId]|stage_cancel|stageId=$stageId")
var allStageStatus: List<BuildStageStatus>? = null
update(buildId, object : ModelInterface {
var update = false

Expand All @@ -203,6 +204,7 @@ class StageBuildDetailService(
stage.stageControlOption = controlOption.stageControlOption
stage.checkIn = checkIn
stage.checkOut = checkOut
allStageStatus = fetchHistoryStageStatus(model)
return Traverse.BREAK
}
return Traverse.CONTINUE
Expand All @@ -212,6 +214,7 @@ class StageBuildDetailService(
return update
}
}, BuildStatus.FAILED)
return allStageStatus ?: emptyList()
}

fun stageReview(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class CheckPauseReviewStageCmd(
commandContext.stage.checkIn?.status = BuildStatus.QUALITY_CHECK_FAIL.name
commandContext.buildStatus = BuildStatus.QUALITY_CHECK_FAIL
commandContext.latestSummary = "s(${stage.stageId}) failed with QUALITY_CHECK_IN"
commandContext.cmdFlowState = CmdFlowState.CONTINUE
commandContext.cmdFlowState = CmdFlowState.FINALLY
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class UpdateStateForStageCmdFinally(
} else if (commandContext.buildStatus.isFinish()) { // 当前Stage结束
if (commandContext.buildStatus == BuildStatus.SKIP) { // 跳过
pipelineStageService.skipStage(userId = event.userId, buildStage = stage)
} else if (commandContext.buildStatus == BuildStatus.QUALITY_CHECK_FAIL) {
pipelineStageService.checkQualityFailStage(userId = event.userId, buildStage = stage)
}
nextOrFinish(event, stage, commandContext)
sendStageEndCallBack(stage, event)
Expand All @@ -112,8 +114,7 @@ class UpdateStateForStageCmdFinally(
val gotoFinal = commandContext.buildStatus.isFailure() ||
commandContext.buildStatus.isCancel() ||
commandContext.fastKill ||
event.source == BS_STAGE_CANCELED_END_SOURCE ||
event.source == BS_STAGE_QUALITY_CHECK_FAIL_END_SOURCE
event.source == BS_STAGE_CANCELED_END_SOURCE

if (gotoFinal) {
nextStage = pipelineStageService.getLastStage(buildId = event.buildId)
Expand Down

0 comments on commit e1d1de9

Please sign in to comment.