Skip to content

Commit

Permalink
Merge pull request #100 from yjieliang/issue-8211
Browse files Browse the repository at this point in the history
Issue 8211
  • Loading branch information
yjieliang committed May 18, 2023
2 parents 8a9047d + 2875d7e commit cefad14
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package com.tencent.devops.common.pipeline.enums

import com.tencent.devops.common.api.pojo.IdValue
import com.tencent.devops.common.api.util.MessageUtil
import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitWebHookTriggerElement
import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGithubWebHookTriggerElement
import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitlabWebHookTriggerElement
Expand All @@ -48,27 +49,34 @@ enum class StartType {
REMOTE;

companion object {
fun toReadableString(type: String, channelCode: ChannelCode?): String {
return when (type) {
StartType.MANUAL.name -> "手动"
StartType.TIME_TRIGGER.name -> "定时"
StartType.WEB_HOOK.name -> "代码变更"
StartType.REMOTE.name -> "远程触发"
fun toReadableString(type: String, channelCode: ChannelCode?, language: String): String {
var params: Array<String>? = null
val name = when (type) {
StartType.MANUAL.name -> MANUAL.name
StartType.TIME_TRIGGER.name -> TIME_TRIGGER.name
StartType.WEB_HOOK.name -> WEB_HOOK.name
StartType.REMOTE.name -> REMOTE.name
StartType.SERVICE.name -> {
if (channelCode != null) {
if (channelCode == ChannelCode.BS) {
"OpenAPI启动"
"${SERVICE.name}_${ChannelCode.BS}"
} else {
channelCode.name + "启动"
params = arrayOf(channelCode.name)
"${SERVICE.name}_CHANNEL"
}
} else {
"第三方启动"
"${SERVICE.name}_NOT_CHANNEL"
}
}
StartType.PIPELINE.name -> "流水线"
StartType.PIPELINE.name -> PIPELINE.name
"" -> ""
else -> type
}
return MessageUtil.getMessageByLocale(
messageCode = "START_TYPE_$name",
language = language,
params = params
)
}

fun toStartType(type: String): StartType {
Expand All @@ -83,10 +91,10 @@ enum class StartType {

private val logger = LoggerFactory.getLogger(StartType::class.java)

fun getStartTypeMap(): List<IdValue> {
fun getStartTypeMap(language: String): List<IdValue> {
val result = mutableListOf<IdValue>()
values().forEach {
result.add(IdValue(it.name, toReadableString(it.name, null)))
result.add(IdValue(it.name, toReadableString(it.name, null, language)))
}

return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ object QualityUtils {

val titleData = mutableListOf(event.status,
DateTimeUtil.formatMilliTime(System.currentTimeMillis() - event.startTime),
StartType.toReadableString(event.triggerType, null),
StartType.toReadableString(
event.triggerType,
null,
I18nUtil.getLanguage(I18nUtil.getRequestUserId())
),
pipelineName,
"${HomeHostUtil.innerServerHost()}/console/pipeline/$projectId/$pipelineId/detail/$buildId",
I18nUtil.getCodeLanMessage(BK_CI_PIPELINE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.tencent.devops.common.pipeline.pojo.element.Element
import com.tencent.devops.common.pipeline.pojo.element.RunCondition
import com.tencent.devops.common.pipeline.utils.ModelUtils
import com.tencent.devops.common.redis.RedisOperation
import com.tencent.devops.common.web.utils.I18nUtil
import com.tencent.devops.process.dao.BuildDetailDao
import com.tencent.devops.process.engine.dao.PipelineBuildDao
import com.tencent.devops.process.engine.dao.PipelineBuildSummaryDao
Expand All @@ -51,13 +52,13 @@ import com.tencent.devops.process.pojo.BuildStageStatus
import com.tencent.devops.process.pojo.pipeline.ModelDetail
import com.tencent.devops.process.service.StageTagService
import com.tencent.devops.process.utils.PipelineVarUtil
import java.time.LocalDateTime
import java.util.concurrent.TimeUnit
import org.jooq.DSLContext
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import java.time.LocalDateTime
import java.util.concurrent.TimeUnit

@Suppress("LongParameterList", "ComplexMethod", "ReturnCount")
@Service
Expand Down Expand Up @@ -162,7 +163,11 @@ class PipelineBuildDetailService @Autowired constructor(
pipelineName = model.name,
userId = record.startUser ?: "",
triggerUser = buildInfo.triggerUser,
trigger = StartType.toReadableString(buildInfo.trigger, buildInfo.channelCode),
trigger = StartType.toReadableString(
buildInfo.trigger,
buildInfo.channelCode,
I18nUtil.getLanguage(I18nUtil.getRequestUserId())
),
startTime = record.startTime?.timestampmilli() ?: LocalDateTime.now().timestampmilli(),
endTime = record.endTime?.timestampmilli(),
status = record.status ?: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,11 @@ class PipelineRuntimeService @Autowired constructor(
BuildHistory(
id = buildId,
userId = triggerUser ?: startUser,
trigger = StartType.toReadableString(trigger, channelCode),
trigger = StartType.toReadableString(
trigger,
channelCode,
I18nUtil.getLanguage(I18nUtil.getRequestUserId())
),
buildNum = buildNum,
pipelineVersion = version,
startTime = startTime?.timestampmilli() ?: 0L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ class PipelineBuildRecordService @Autowired constructor(
language = I18nUtil.getDefaultLocaleLanguage()
)
} else {
StartType.toReadableString(buildInfo.trigger, buildInfo.channelCode)
StartType.toReadableString(
buildInfo.trigger,
buildInfo.channelCode,
I18nUtil.getLanguage(I18nUtil.getRequestUserId())
)
}
val queueTime = buildRecordModel?.queueTime?.timestampmilli() ?: buildInfo.queueTime
val startTime = buildRecordModel?.startTime?.timestampmilli()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ import com.tencent.devops.common.web.utils.AtomRuntimeUtil
import com.tencent.devops.common.web.utils.I18nUtil
import com.tencent.devops.common.websocket.enum.RefreshType
import com.tencent.devops.engine.api.pojo.HeartBeatInfo
import com.tencent.devops.process.constant.ProcessMessageCode.BK_CONTINUE_WHEN_ERROR
import com.tencent.devops.process.constant.ProcessMessageCode.BK_PROCESSING_CURRENT_REPORTED_TASK_PLEASE_WAIT
import com.tencent.devops.process.constant.ProcessMessageCode.BK_VM_START_ALREADY
import com.tencent.devops.process.engine.common.Timeout
import com.tencent.devops.process.engine.common.Timeout.transMinuteTimeoutToMills
import com.tencent.devops.process.engine.common.Timeout.transMinuteTimeoutToSec
Expand Down Expand Up @@ -88,21 +90,19 @@ import com.tencent.devops.process.service.BuildVariableService
import com.tencent.devops.process.service.PipelineAsCodeService
import com.tencent.devops.process.service.PipelineContextService
import com.tencent.devops.process.service.PipelineTaskPauseService
import com.tencent.devops.process.constant.ProcessMessageCode.BK_VM_START_ALREADY
import com.tencent.devops.process.constant.ProcessMessageCode.BK_CONTINUE_WHEN_ERROR
import com.tencent.devops.process.util.TaskUtils
import com.tencent.devops.process.utils.PIPELINE_BUILD_REMARK
import com.tencent.devops.process.utils.PIPELINE_ELEMENT_ID
import com.tencent.devops.process.utils.PIPELINE_VMSEQ_ID
import com.tencent.devops.process.utils.PipelineVarUtil
import com.tencent.devops.store.api.container.ServiceContainerAppResource
import com.tencent.devops.store.pojo.app.BuildEnv
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import java.time.LocalDateTime
import java.util.concurrent.TimeUnit
import javax.ws.rs.NotFoundException
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

@Suppress(
"LongMethod",
Expand Down Expand Up @@ -936,18 +936,6 @@ class EngineVMBuildService @Autowired(required = false) constructor(
task?.run {
errorType?.also { // #5046 增加错误信息
val errMsg = "Error: Process completed with exit code $errorCode: $errorMsg. " +
(
errorCode?.let {
"\n${
I18nUtil.getCodeLanMessage(
messageCode = errorCode.toString(),
checkUrlDecoder = true,
language = I18nUtil.getDefaultLocaleLanguage()
)
}\n"
}
?: ""
) +
when (errorType) {
ErrorType.USER -> "Please check your input or service."
ErrorType.THIRD_PARTY -> "Please contact the third-party service provider."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.tencent.devops.process.permission.notify
import com.tencent.devops.common.client.Client
import com.tencent.devops.common.pipeline.enums.ChannelCode
import com.tencent.devops.common.pipeline.enums.StartType
import com.tencent.devops.common.web.utils.I18nUtil
import com.tencent.devops.process.engine.service.PipelineRepositoryService
import com.tencent.devops.process.engine.service.PipelineRuntimeService
import com.tencent.devops.process.notify.command.ExecutionVariables
Expand Down Expand Up @@ -68,7 +69,11 @@ class BluekingNotifyPipelineCmd @Autowired constructor(
}
}

val trigger = StartType.toReadableString(triggerType, channelCode)
val trigger = StartType.toReadableString(
triggerType,
channelCode,
I18nUtil.getLanguage(I18nUtil.getRequestUserId())
)
return ExecutionVariables(pipelineVersion = pipelineVersion,
buildNum = buildNum,
trigger = trigger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,7 @@ class PipelineBuildFacadeService(
arrayOf(userId, pipelineId, I18nUtil.getCodeLanMessage(BK_BUILD_HISTORY))
)
)
return StartType.getStartTypeMap()
return StartType.getStartTypeMap(I18nUtil.getLanguage(I18nUtil.getRequestUserId()))
}

fun getHistoryConditionRepo(userId: String, projectId: String, pipelineId: String): List<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ package com.tencent.devops.worker.common.task.script
import com.tencent.bkrepo.repository.pojo.token.TokenType
import com.tencent.devops.common.api.exception.TaskExecuteException
import com.tencent.devops.common.api.pojo.ErrorCode
import com.tencent.devops.common.api.pojo.ErrorCode.USER_SCRIPT_TASK_FAIL
import com.tencent.devops.common.api.pojo.ErrorType
import com.tencent.devops.common.api.util.MessageUtil
import com.tencent.devops.common.pipeline.pojo.element.agent.LinuxScriptElement
import com.tencent.devops.common.pipeline.pojo.element.agent.WindowsScriptElement
import com.tencent.devops.common.web.utils.I18nUtil
import com.tencent.devops.process.pojo.BuildTask
import com.tencent.devops.process.pojo.BuildVariables
import com.tencent.devops.process.utils.PIPELINE_START_USER_ID
Expand Down Expand Up @@ -149,9 +151,12 @@ open class ScriptTask : ITask() {
)
}
}
val errorMsg = if (ignore is TaskExecuteException) {
val errorMsg = (if (ignore is TaskExecuteException) {
ignore.errorMsg
} else ""
} else "") + I18nUtil.getCodeLanMessage(
messageCode = "$USER_SCRIPT_TASK_FAIL",
language = I18nUtil.getDefaultLocaleLanguage()
)

throw TaskExecuteException(
errorMsg = errorMsg,
Expand Down
12 changes: 10 additions & 2 deletions support-files/i18n/message_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@
2199006=User atom execution timeout (self-limiting)
2199007=Quality check failed
2199009=script command did not execute properly
2199010=Termination of execution due to user configuration of Fast Kill
2199011=A user error occurred in the bash script
2199010=Stage FastKill
2199011=%1B[1;31m The answer to this question may be found in <a target=%22_blank%22<a>>BASH_FAQ%1B[m%0A========TroubleshootingTips========%0A When the script exit code is not 0, the execution fails. Analysis can be done from the following path: %0A1. Troubleshoot %0A2 based on the error log. Manually execute the script locally. If the local execution also fails, it is likely a script logic problem; If the local OK is OK, troubleshoot the build environment (such as environment dependencies or code changes)
2199501=Third-party interface call error
2199502=Third-party build environment errors

Expand Down Expand Up @@ -396,3 +396,11 @@ buildType.STREAM=stream
buildType.AGENT_LESS=No compilation environment
language.zh_CN=Simplified Chinese
language.en_US=English
START_TYPE_MANUAL=manual
START_TYPE_TIME_TRIGGER=timing
START_TYPE_WEB_HOOK=Code changes
START_TYPE_SERVICE_BS=Openapi start
START_TYPE_SERVICE_CHANNEL={0} start
START_TYPE_SERVICE_NOT_CHANNEL=Third-party start
START_TYPE_PIPELINE=pipeline
START_TYPE_REMOTE=remote triggering
12 changes: 10 additions & 2 deletions support-files/i18n/message_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@
2199006=用户插件执行超时(自行限制)
2199007=质量红线检查失败
2199009=脚本命令无法正常执行
2199010=因用户配置了FastKill导致的终止执行
2199011=bash脚本发生用户错误
2199010=因Stage配置了Stage FastKill,在其他插件失败引发当前插件被提前终止而失败
2199011=%1B[1;31m这个问题也许可以从<a target=%22_blank%22>BASH_FAQ</a>中找到答案%1B[m%0A========问题排查Tips========%0A当脚本退出码非0时,执行失败。可以从以下路径进行分析:%0A1. 根据错误日志排查%0A2. 在本地手动执行脚本。如果本地执行也失败,很可能是脚本逻辑问题;如果本地OK,排查构建环境(比如环境依赖、或者代码变更等)
2199501=第三方接口调用错误
2199502=第三方构建环境错误

Expand Down Expand Up @@ -396,3 +396,11 @@ buildType.STREAM=stream
buildType.AGENT_LESS=无编译环境
language.zh_CN=简体中文
language.en_US=英文
START_TYPE_MANUAL=手动
START_TYPE_TIME_TRIGGER=定时
START_TYPE_WEB_HOOK=代码变更
START_TYPE_SERVICE_BS=Openapi启动
START_TYPE_SERVICE_CHANNEL={0}启动
START_TYPE_SERVICE_NOT_CHANNEL=第三方启动
START_TYPE_PIPELINE=流水线
START_TYPE_REMOTE=远程触发

0 comments on commit cefad14

Please sign in to comment.