Skip to content

Commit

Permalink
Merge pull request #6690 from royalhuang/issue_6646
Browse files Browse the repository at this point in the history
bug: 修复重试和任务认领失败的逻辑问题 #6646 [补充]
  • Loading branch information
irwinsun authored May 7, 2022
2 parents d436560 + 1f88e0f commit 97b7f9d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,19 @@ interface BuildJobResource {
@ApiParam(value = "执行结果", required = true)
errorInfo: ErrorInfo
): Result<Boolean>

@ApiOperation("获取当前构建的构建详情页")
@GET
@Path("/detail_url")
fun getBuildDetailUrl(
@ApiParam("projectId", required = true)
@HeaderParam(AUTH_HEADER_DEVOPS_PROJECT_ID)
projectId: String,
@ApiParam("pipelineId", required = true)
@HeaderParam(AUTH_HEADER_DEVOPS_PIPELINE_ID)
pipelineId: String,
@ApiParam(value = "构建ID", required = true)
@HeaderParam(AUTH_HEADER_DEVOPS_BUILD_ID)
buildId: String
): Result<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.tencent.devops.common.pipeline.enums.BuildStatus
import com.tencent.devops.common.web.RestResource
import com.tencent.devops.engine.api.BuildJobResource
import com.tencent.devops.engine.api.pojo.HeartBeatInfo
import com.tencent.devops.process.bean.PipelineUrlBean
import com.tencent.devops.process.engine.service.vmbuild.EngineVMBuildService
import com.tencent.devops.process.pojo.BuildTask
import com.tencent.devops.process.pojo.BuildTaskResult
Expand All @@ -44,7 +45,8 @@ import org.springframework.beans.factory.annotation.Autowired
@Suppress("UNUSED")
@RestResource
class BuildJobResourceImpl @Autowired constructor(
private val vMBuildService: EngineVMBuildService
private val vMBuildService: EngineVMBuildService,
private val pipelineUrlBean: PipelineUrlBean
) : BuildJobResource {

override fun jobStarted(
Expand Down Expand Up @@ -173,6 +175,10 @@ class BuildJobResourceImpl @Autowired constructor(
return Result(true)
}

override fun getBuildDetailUrl(projectId: String, pipelineId: String, buildId: String): Result<String> {
return Result(pipelineUrlBean.genBuildDetailUrl(projectId, pipelineId, buildId, null, null, true))
}

companion object {
private fun checkParam(buildId: String, vmSeqId: String, vmName: String, retryCount: String? = null) {
if (buildId.isBlank()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ interface EngineBuildSDKApi : WorkerRestApiSDK {

fun getJobContext(): Map<String, String>

fun getBuildDetailUrl(): String
fun getBuildDetailUrl(): Result<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ open class EngineBuildResourceApi : AbstractBuildResourceApi(), EngineBuildSDKAp
return emptyMap()
}

override fun getBuildDetailUrl(): String {
val path = getRequestUrl(path = "api/build/builds/detail_url")
override fun getBuildDetailUrl(): Result<String> {
val path = getRequestUrl(path = "api/build/worker/detail_url")
val request = buildGet(path)
val errorMessage = "构建超时结束请求失败"
val responseContent = try {
Expand All @@ -161,7 +161,7 @@ open class EngineBuildResourceApi : AbstractBuildResourceApi(), EngineBuildSDKAp
writeTimeoutInSec = 30L
)
} catch (ignore: Throwable) {
return ""
return Result("")
}
return objectMapper.readValue(responseContent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,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()
jobContext[CI_BUILD_URL] = buildApi.getBuildDetailUrl().data ?: ""
return ret.copy(variables = ret.variables.plus(jobContext))
}

Expand Down
2 changes: 1 addition & 1 deletion support-files/templates/#etc#ci#common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ spring:
spring:
rabbitmq:
virtual-host: __BK_CI_RABBITMQ_VHOST__
username: __BK_CI_RABBITMQ_VHOST__
username: __BK_CI_RABBITMQ_USER__
password: __BK_CI_RABBITMQ_PASSWORD__
addresses: __BK_CI_RABBITMQ_ADDR__
# extend-pulsar:
Expand Down

0 comments on commit 97b7f9d

Please sign in to comment.