diff --git a/src/backend/ci/core/common/common-pipeline-yaml/src/main/kotlin/com/tencent/devops/process/yaml/transfer/StageTransfer.kt b/src/backend/ci/core/common/common-pipeline-yaml/src/main/kotlin/com/tencent/devops/process/yaml/transfer/StageTransfer.kt index 2cd0896da97..f65334c7d86 100644 --- a/src/backend/ci/core/common/common-pipeline-yaml/src/main/kotlin/com/tencent/devops/process/yaml/transfer/StageTransfer.kt +++ b/src/backend/ci/core/common/common-pipeline-yaml/src/main/kotlin/com/tencent/devops/process/yaml/transfer/StageTransfer.kt @@ -298,6 +298,7 @@ class StageTransfer @Autowired(required = false) constructor( } } return PreStage( + enable = stage.isStageEnable().nullIfDefault(true), name = stage.name, label = maskYamlStageLabel(stage.tag).ifEmpty { null }, ifField = when (stage.stageControlOption?.runCondition) { diff --git a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/service/StreamPipelineService.kt b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/service/StreamPipelineService.kt index 4300ec6fac0..77f37ee70ac 100644 --- a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/service/StreamPipelineService.kt +++ b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/service/StreamPipelineService.kt @@ -33,12 +33,13 @@ import com.tencent.devops.common.api.util.PageUtil import com.tencent.devops.common.client.Client import com.tencent.devops.common.pipeline.Model import com.tencent.devops.common.pipeline.enums.ChannelCode +import com.tencent.devops.common.pipeline.pojo.PipelineModelAndSetting import com.tencent.devops.common.redis.RedisLock import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.model.stream.tables.records.TGitPipelineResourceRecord import com.tencent.devops.process.api.service.ServicePipelineResource -import com.tencent.devops.common.pipeline.pojo.PipelineModelAndSetting import com.tencent.devops.process.yaml.v2.utils.ScriptYmlUtils +import com.tencent.devops.project.api.service.ServiceProjectResource import com.tencent.devops.stream.config.StreamGitConfig import com.tencent.devops.stream.dao.GitPipelineResourceDao import com.tencent.devops.stream.dao.GitRequestEventBuildDao @@ -391,6 +392,13 @@ class StreamPipelineService @Autowired constructor( gitProjectId = gitProjectId.toLong(), scmType = gitConfig.getScmType() ) + val pipelineAsCodeSettings = try { + client.get(ServiceProjectResource::class).get(gitProjectCode) + .data?.properties?.pipelineAsCodeSettings + } catch (ignore: Throwable) { + logger.warn("StreamYamlTrigger get project[$gitProjectCode] as code settings error.", ignore) + null + } val realPipeline: StreamTriggerPipeline // 避免出现多个触发拿到空的pipelineId后依次进来创建,所以需要在锁后重新获取pipeline triggerLock.use { @@ -404,7 +412,10 @@ class StreamPipelineService @Autowired constructor( userId = userId, gitProjectId = gitProjectId.toLong(), projectCode = gitProjectCode, - modelAndSetting = StreamPipelineUtils.createEmptyPipelineAndSetting(realPipeline.displayName), + modelAndSetting = StreamPipelineUtils.createEmptyPipelineAndSetting( + realPipeline.displayName, + pipelineAsCodeSettings + ), updateLastModifyUser = true, branch = branch, // 空model计算md5没有意义,直接传空 diff --git a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/StreamYamlBaseBuild.kt b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/StreamYamlBaseBuild.kt index 45351cb3065..70022bec968 100644 --- a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/StreamYamlBaseBuild.kt +++ b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/StreamYamlBaseBuild.kt @@ -34,6 +34,7 @@ import com.tencent.devops.common.event.dispatcher.pipeline.PipelineEventDispatch import com.tencent.devops.common.pipeline.Model import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.pipeline.pojo.BuildParameters +import com.tencent.devops.common.pipeline.pojo.PipelineModelAndSetting import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.model.stream.tables.records.TGitPipelineResourceRecord @@ -45,7 +46,6 @@ import com.tencent.devops.process.pojo.BuildId import com.tencent.devops.process.pojo.BuildTemplateAcrossInfo import com.tencent.devops.process.pojo.TemplateAcrossInfoType import com.tencent.devops.process.pojo.code.PipelineBuildCommit -import com.tencent.devops.common.pipeline.pojo.PipelineModelAndSetting import com.tencent.devops.process.pojo.webhook.WebhookTriggerParams import com.tencent.devops.process.utils.PIPELINE_NAME import com.tencent.devops.process.yaml.v2.enums.TemplateType @@ -262,7 +262,10 @@ class StreamYamlBaseBuild @Autowired constructor( userId = pipeline.creator ?: "", gitProjectId = gitProjectId.toLong(), projectCode = projectCode, - modelAndSetting = StreamPipelineUtils.createEmptyPipelineAndSetting(pipeline.displayName), + modelAndSetting = StreamPipelineUtils.createEmptyPipelineAndSetting( + pipeline.displayName, + action.data.context.pipelineAsCodeSettings + ), updateLastModifyUser = true ) streamPipelineBranchService.saveOrUpdate( diff --git a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/StreamYamlBuild.kt b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/StreamYamlBuild.kt index 2d8fd82c68e..a63d923000c 100644 --- a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/StreamYamlBuild.kt +++ b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/StreamYamlBuild.kt @@ -187,7 +187,10 @@ class StreamYamlBuild @Autowired constructor( userId = action.data.getUserId(), gitProjectId = action.data.eventCommon.gitProjectId.toLong(), projectCode = action.getProjectCode(), - modelAndSetting = StreamPipelineUtils.createEmptyPipelineAndSetting(realPipeline.displayName), + modelAndSetting = StreamPipelineUtils.createEmptyPipelineAndSetting( + realPipeline.displayName, + action.data.context.pipelineAsCodeSettings + ), updateLastModifyUser = true ) } @@ -235,6 +238,7 @@ class StreamYamlBuild @Autowired constructor( TriggerReason.PIPELINE_PREPARE_ERROR ) } + is QualityRulesException -> { Triple( false, @@ -246,6 +250,7 @@ class StreamYamlBuild @Autowired constructor( is StreamTriggerBaseException, is ErrorCodeException -> { throw e } + else -> { logger.warn("StreamYamlBuild|gitStartBuild|${action.data.context.requestEventId}|error", e) Triple(false, e.message, TriggerReason.UNKNOWN_ERROR) diff --git a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/StreamYamlTrigger.kt b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/StreamYamlTrigger.kt index 524d3ad9560..0ef89ff7fef 100644 --- a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/StreamYamlTrigger.kt +++ b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/StreamYamlTrigger.kt @@ -199,6 +199,24 @@ class StreamYamlTrigger @Autowired constructor( ) var pipeline = action.data.context.pipeline!! + // 获取蓝盾流水线的pipelineAsCodeSetting + val projectCode = GitCommonUtils.getCiProjectId(pipeline.gitProjectId.toLong(), streamGitConfig.getScmType()) + action.data.context.pipelineAsCodeSettings = try { + if (pipeline.pipelineId.isNotBlank()) { + client.get(ServicePipelineSettingResource::class).getPipelineSetting( + projectId = projectCode, + pipelineId = pipeline.pipelineId, + channelCode = ChannelCode.GIT + ).data?.pipelineAsCodeSettings + } else { + client.get(ServiceProjectResource::class).get(projectCode) + .data?.properties?.pipelineAsCodeSettings + } + } catch (ignore: Throwable) { + logger.warn("StreamYamlTrigger get project[$projectCode] as code settings error.", ignore) + null + } + // 提前创建新流水线,保证git提交后 stream上能看到 if (pipeline.pipelineId.isBlank()) { pipeline = StreamTriggerPipeline( @@ -225,24 +243,6 @@ class StreamYamlTrigger @Autowired constructor( ) } - // 获取蓝盾流水线的pipelineAsCodeSetting - val projectCode = GitCommonUtils.getCiProjectId(pipeline.gitProjectId.toLong(), streamGitConfig.getScmType()) - action.data.context.pipelineAsCodeSettings = try { - if (pipeline.pipelineId.isNotBlank()) { - client.get(ServicePipelineSettingResource::class).getPipelineSetting( - projectId = projectCode, - pipelineId = pipeline.pipelineId, - channelCode = ChannelCode.GIT - ).data?.pipelineAsCodeSettings - } else { - client.get(ServiceProjectResource::class).get(projectCode) - .data?.properties?.pipelineAsCodeSettings - } - } catch (ignore: Throwable) { - logger.warn("StreamYamlTrigger get project[$projectCode] as code settings error.", ignore) - null - } - // 拼接插件时会需要传入GIT仓库信息需要提前刷新下状态,只有url或者名称不对才更新 val gitProjectInfo = action.api.getGitProjectInfo( action.getGitCred(), diff --git a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/util/StreamPipelineUtils.kt b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/util/StreamPipelineUtils.kt index b6772051f59..0c55d9041e7 100644 --- a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/util/StreamPipelineUtils.kt +++ b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/util/StreamPipelineUtils.kt @@ -33,11 +33,11 @@ import com.tencent.devops.common.api.pojo.PipelineAsCodeSettings import com.tencent.devops.common.pipeline.Model import com.tencent.devops.common.pipeline.container.Stage import com.tencent.devops.common.pipeline.container.TriggerContainer +import com.tencent.devops.common.pipeline.pojo.PipelineModelAndSetting import com.tencent.devops.common.pipeline.pojo.element.trigger.ManualTriggerElement +import com.tencent.devops.common.pipeline.pojo.setting.PipelineSetting import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.process.engine.common.VMUtils -import com.tencent.devops.common.pipeline.pojo.PipelineModelAndSetting -import com.tencent.devops.common.pipeline.pojo.setting.PipelineSetting @Suppress("LongParameterList", "ReturnCount") object StreamPipelineUtils { @@ -66,38 +66,39 @@ object StreamPipelineUtils { messageId: String ) = "$streamUrl/notifications?id=$messageId#$gitProjectId" - fun createEmptyPipelineAndSetting(displayName: String) = PipelineModelAndSetting( - model = Model( - name = displayName, - desc = "", - stages = listOf( - Stage( - id = VMUtils.genStageId(1), - name = VMUtils.genStageId(1), - containers = listOf( - TriggerContainer( - id = "0", - name = I18nUtil.getCodeLanMessage( - messageCode = BK_BUILD_TRIGGER, - language = I18nUtil.getDefaultLocaleLanguage() - ), - elements = listOf( - ManualTriggerElement( - name = I18nUtil.getCodeLanMessage( - messageCode = BK_MANUAL_TRIGGER, - language = I18nUtil.getDefaultLocaleLanguage() - ), - id = "T-1-1-1" + fun createEmptyPipelineAndSetting(displayName: String, pipelineAsCodeSettings: PipelineAsCodeSettings?) = + PipelineModelAndSetting( + model = Model( + name = displayName, + desc = "", + stages = listOf( + Stage( + id = VMUtils.genStageId(1), + name = VMUtils.genStageId(1), + containers = listOf( + TriggerContainer( + id = "0", + name = I18nUtil.getCodeLanMessage( + messageCode = BK_BUILD_TRIGGER, + language = I18nUtil.getDefaultLocaleLanguage() + ), + elements = listOf( + ManualTriggerElement( + name = I18nUtil.getCodeLanMessage( + messageCode = BK_MANUAL_TRIGGER, + language = I18nUtil.getDefaultLocaleLanguage() + ), + id = "T-1-1-1" + ) ) ) ) ) ) + ), + setting = PipelineSetting( + cleanVariablesWhenRetry = true, + pipelineAsCodeSettings = pipelineAsCodeSettings ?: PipelineAsCodeSettings() ) - ), - setting = PipelineSetting( - cleanVariablesWhenRetry = true, - pipelineAsCodeSettings = PipelineAsCodeSettings() ) - ) }