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 cc25920 commit b9258c0
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class PipelineBuildFacadeService(
}

// 运行中的task重试走全新的处理逻辑
if (!buildInfo.status.isFinish()) {
if (!buildInfo.status.isFinish() && buildInfo.status != BuildStatus.STAGE_SUCCESS) {
if (pipelineRetryFacadeService.runningBuildTaskRetry(
userId = userId,
projectId = projectId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ package com.tencent.devops.stream.common

object CommonVariables {
const val CI_PIPELINE_NAME = "ci.pipeline_name"
const val CI_BUILD_URL = "ci.build_url"
const val CI_ACTOR = "ci.actor"
const val CI_REPO = "ci.repo"
const val CI_REPO_NAME = "ci.repo_name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class StreamYamlBuild @Autowired constructor(
private val deleteEventService: DeleteEventService,
private val streamTriggerCache: StreamTriggerCache,
private val repoTriggerEventService: RepoTriggerEventService,
private val streamGitConfig: StreamGitConfig,
private val pipelineResourceDao: GitPipelineResourceDao,
private val modelCreate: ModelCreate
) {
Expand Down Expand Up @@ -384,8 +383,7 @@ class StreamYamlBuild @Autowired constructor(
yaml = yaml,
streamGitProjectInfo = streamGitProjectInfo,
webhookParams = webhookParams,
yamlTransferData = yamlTransferData,
streamUrl = streamGitConfig.streamUrl
yamlTransferData = yamlTransferData
)

val modelCreateEvent = ModelCreateEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ object ModelParameters {
streamGitProjectInfo: StreamGitProjectCache,
webhookParams: Map<String, String> = mapOf(),
yamlTransferData: YamlTransferData? = null,
streamUrl: String?
): MutableList<BuildFormProperty> {
val result = mutableListOf<BuildFormProperty>()

Expand All @@ -72,7 +71,6 @@ object ModelParameters {

// 通用参数
startParams[CommonVariables.CI_PIPELINE_NAME] = yaml.name ?: ""
startParams[CommonVariables.CI_BUILD_URL] = streamUrl ?: ""
startParams[BK_CI_RUN] = "true"
startParams[CommonVariables.CI_ACTOR] = if (action.metaData.streamObjectKind == StreamObjectKind.SCHEDULE) {
"system"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const val WORKSPACE_CONTEXT = "ci.workspace"

const val CI_TOKEN_CONTEXT = "ci.token"

const val CI_BUILD_URL = "ci.build_url"

const val JOB_OS_CONTEXT = "job.os"

const val SLAVE_AGENT_START_FILE = "devops.slave.agent.start.file"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,17 @@ open class EngineBuildResourceApi : AbstractBuildResourceApi(), EngineBuildSDKAp
val path = getRequestUrl(path = "api/build/builds/detail_url")
val request = buildGet(path)
val errorMessage = "构建超时结束请求失败"
val responseContent = request(
request = request,
connectTimeoutInSec = 5L,
errorMessage = errorMessage,
readTimeoutInSec = 30L,
writeTimeoutInSec = 30L
)
val responseContent = try {
request(
request = request,
connectTimeoutInSec = 5L,
errorMessage = errorMessage,
readTimeoutInSec = 30L,
writeTimeoutInSec = 30L
)
} catch (ignore: Throwable) {
return ""
}
return objectMapper.readValue(responseContent)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.tencent.devops.engine.api.pojo.HeartBeatInfo
import com.tencent.devops.process.pojo.BuildTask
import com.tencent.devops.process.pojo.BuildTaskResult
import com.tencent.devops.process.pojo.BuildVariables
import com.tencent.devops.worker.common.CI_BUILD_URL
import com.tencent.devops.worker.common.JOB_OS_CONTEXT
import com.tencent.devops.worker.common.api.ApiFactory
import com.tencent.devops.worker.common.api.engine.EngineBuildSDKApi
Expand Down Expand Up @@ -69,7 +70,7 @@ object EngineService {
// #5277 将Job上下文传入本次agent任务
val jobContext = buildApi.getJobContext().toMutableMap()
jobContext[JOB_OS_CONTEXT] = AgentEnv.getOS().name

jobContext[CI_BUILD_URL] = buildApi.getBuildDetailUrl()
return ret.copy(variables = ret.variables.plus(jobContext))
}

Expand Down

0 comments on commit b9258c0

Please sign in to comment.