Skip to content

Commit

Permalink
feat: 流水线插件高级特性:即使前面有插件运行失败也运行,即使被取消也运行 TencentBlueKing#1156
Browse files Browse the repository at this point in the history
  • Loading branch information
carlyin0801 committed Jul 21, 2021
1 parent 01e8b4f commit b0d92b7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ data class ElementAdditionalOptions(
enum class RunCondition {
PRE_TASK_SUCCESS, // 所有前置插件运行成功时
PRE_TASK_FAILED_BUT_CANCEL, // 即使前面有插件运行失败也运行,除非被取消才不运行
PRE_TASK_FAILED_EVEN_CANCEL, // 即使前面有插件运行失败也运行,即使被取消也运行 [未实现]
PRE_TASK_FAILED_EVEN_CANCEL, // 即使前面有插件运行失败也运行,即使被取消也运行
PRE_TASK_FAILED_ONLY, // 只有前面有插件运行失败时才运行
OTHER_TASK_RUNNING, // 指定插件开始运行时 [未实现]
CUSTOM_VARIABLE_MATCH, // 自定义变量全部满足时运行
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ object ModelUtils {
element.canRetry = null // 自动跳过的不能手动重试
}
} else if (additionalOptions.runCondition == RunCondition.PRE_TASK_FAILED_ONLY ||
additionalOptions.runCondition == RunCondition.PRE_TASK_FAILED_BUT_CANCEL
additionalOptions.runCondition == RunCondition.PRE_TASK_FAILED_BUT_CANCEL ||
additionalOptions.runCondition == RunCondition.PRE_TASK_FAILED_EVEN_CANCEL
) {
// 前面有失败的插件时也要运行的插件,将前面的失败插件置为不可重试和跳过
element.canRetry = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ object ControlUtils {
additionalOptions?.runCondition == RunCondition.PRE_TASK_FAILED_BUT_CANCEL -> {
skip = containerFinalStatus.isCancel()
}
// 即使前面有插件运行失败也运行,即使被取消也运行 [未实现] 永远不跳过
// 即使前面有插件运行失败也运行,即使被取消也运行 永远不跳过
additionalOptions?.runCondition == RunCondition.PRE_TASK_FAILED_EVEN_CANCEL -> skip = false
// 如果容器是失败状态,[其他条件] 都要跳过不执行
containerFinalStatus.isFailure() -> skip = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.tencent.devops.common.pipeline.container.Container
import com.tencent.devops.common.pipeline.container.Stage
import com.tencent.devops.common.pipeline.enums.BuildStatus
import com.tencent.devops.common.pipeline.pojo.element.Element
import com.tencent.devops.common.pipeline.pojo.element.RunCondition
import com.tencent.devops.common.pipeline.pojo.element.agent.ManualReviewUserTaskElement
import com.tencent.devops.common.pipeline.pojo.element.quality.QualityGateInElement
import com.tencent.devops.common.pipeline.pojo.element.quality.QualityGateOutElement
Expand Down Expand Up @@ -294,7 +295,7 @@ class TaskBuildDetailService(
val startIndex = endElementIndex + 1
val endIndex = elements.size - 1
if (endIndex >= startIndex) {
addUpdateTaskStatusInfo(
addCancelTaskStatusInfo(
startIndex = startIndex,
endIndex = endIndex,
elements = elements,
Expand Down Expand Up @@ -322,7 +323,7 @@ class TaskBuildDetailService(
val parentElement = elements[parentElementJobIndex]
val taskStatus = BuildStatus.parse(parentElement.status)
if (!(taskStatus.isFinish() || parentElement.id == endElement.id)) {
handleUpdateTaskStatusInfo(
handleCancelTaskStatusInfo(
tmpElementIndex = tmpElementIndex,
elements = elements,
endElementIndex = endElementIndex,
Expand All @@ -336,7 +337,7 @@ class TaskBuildDetailService(
if (endIndex < startIndex) {
return true
}
addUpdateTaskStatusInfo(
addCancelTaskStatusInfo(
startIndex = startIndex,
endIndex = endIndex,
elements = elements,
Expand All @@ -347,7 +348,7 @@ class TaskBuildDetailService(
return false
}

private fun handleUpdateTaskStatusInfo(
private fun handleCancelTaskStatusInfo(
tmpElementIndex: Int,
elements: List<Element>,
endElementIndex: Int,
Expand All @@ -357,7 +358,7 @@ class TaskBuildDetailService(
val startIndex = endElementIndex + 1
val endIndex = elements.size - 1
if (endIndex > startIndex) {
addUpdateTaskStatusInfo(
addCancelTaskStatusInfo(
startIndex = startIndex,
endIndex = endIndex,
elements = elements,
Expand All @@ -367,21 +368,23 @@ class TaskBuildDetailService(
}
}

private fun addUpdateTaskStatusInfo(
private fun addCancelTaskStatusInfo(
startIndex: Int,
endIndex: Int,
elements: List<Element>,
updateTaskStatusInfos: MutableList<Map<String, Any>>?
) {
for (i in startIndex..endIndex) {
val unExecElement = elements[i]
val unExecTaskId = unExecElement.id
val unExecBuildStatus = BuildStatus.UNEXEC
unExecElement.status = unExecBuildStatus.name
if (unExecTaskId != null) {
val element = elements[i]
val taskId = element.id
val runCondition = element.additionalOptions?.runCondition
if (taskId != null && runCondition != RunCondition.PRE_TASK_FAILED_EVEN_CANCEL) {
// 把runCondition不为PRE_TASK_FAILED_EVEN_CANCEL的任务的状态置为UNEXEC
val unExecBuildStatus = BuildStatus.UNEXEC
element.status = unExecBuildStatus.name
updateTaskStatusInfos?.add(
mapOf(
PIPELINE_ELEMENT_ID to unExecTaskId,
PIPELINE_ELEMENT_ID to taskId,
BUILD_STATUS to unExecBuildStatus
)
)
Expand Down

0 comments on commit b0d92b7

Please sign in to comment.