Skip to content

Commit

Permalink
bug: 修复重试和任务认领失败的逻辑问题 TencentBlueKing#6646
Browse files Browse the repository at this point in the history
  • Loading branch information
royalhuang committed Apr 28, 2022
1 parent b9258c0 commit ebf90c0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -119,8 +121,9 @@ class PipelineContextService @Autowired constructor(
return contextMap
}

fun buildContextToNotice(
fun buildFinishContext(
projectId: String,
pipelineId: String,
buildId: String
): Map<String, String> {
val modelDetail = pipelineBuildDetailService.get(projectId, buildId) ?: return emptyMap()
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@ class ServiceVarResourceImpl @Autowired constructor(
}
}

override fun getContextVar(projectId: String, buildId: String, contextName: String?): Result<Map<String, String>> {
override fun getContextVar(
projectId: String,
pipelineId: String,
buildId: String,
contextName: String?
): Result<Map<String, String>> {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ebf90c0

Please sign in to comment.