diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/pipeline/PipelineBuildService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/pipeline/PipelineBuildService.kt index 9b738632ae1..9d70c36932c 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/pipeline/PipelineBuildService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/pipeline/PipelineBuildService.kt @@ -194,11 +194,7 @@ class PipelineBuildService( ) val pipelineDialectType = PipelineDialectUtil.getPipelineDialectType(channelCode = channelCode, asCodeSettings = asCodeSettings) - // 校验流水线启动变量长度 - checkBuildVariablesLength( - pipelineDialect = pipelineDialectType.dialect, - startValues = startValues - ) + // 如果指定了版本号,则设置指定的版本号 pipeline.version = signPipelineVersion ?: pipeline.version val originModelStr = JsonUtil.toJson(model, formatted = false) @@ -254,6 +250,11 @@ class PipelineBuildService( versionName = versionName, yamlVersion = yamlVersion ) + // 校验流水线启动变量长度 + checkBuildParameterLength( + pipelineDialect = pipelineDialectType.dialect, + buildParameters = context.buildParameters + ) val interceptResult = pipelineInterceptorChain.filter( InterceptData( @@ -430,14 +431,14 @@ class PipelineBuildService( // return originStartParams } - private fun checkBuildVariablesLength( + private fun checkBuildParameterLength( pipelineDialect: IPipelineDialect, - startValues: Map? + buildParameters: List ) { - val longVarNames = startValues?.filter { - it.value.length >= PIPELINE_VARIABLES_STRING_LENGTH_MAX - }?.map { it.key } - if (!longVarNames.isNullOrEmpty() && !pipelineDialect.supportLongVarValue()) { + val longVarNames = buildParameters.filter { + it.value.toString().length >= PIPELINE_VARIABLES_STRING_LENGTH_MAX + }.map { it.key } + if (longVarNames.isNotEmpty() && !pipelineDialect.supportLongVarValue()) { throw ErrorCodeException( errorCode = ProcessMessageCode.ERROR_PIPELINE_VARIABLES_OUT_OF_LENGTH, params = arrayOf(longVarNames.toString()) diff --git a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/ITask.kt b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/ITask.kt index df10c563373..d7aae3b2bfd 100644 --- a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/ITask.kt +++ b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/ITask.kt @@ -66,7 +66,8 @@ abstract class ITask { private lateinit var dialect: IPipelineDialect companion object { - private const val ENGLISH_NAME_PATTERN = "[A-Za-z_][A-Za-z_0-9.]*" + // 有的插件输出的变量会带taskId,taskId包含-,所以需要保留 + private const val ENGLISH_NAME_PATTERN = "[A-Za-z_][A-Za-z_0-9.-]*" } fun run( @@ -109,22 +110,20 @@ abstract class ITask { protected fun addEnv(env: Map) { var errReadOnlyFlag = false var errLongValueFlag = false + val errLongValueVars = mutableSetOf() var errChineseVarName = false + val errChineseVars = mutableSetOf() env.forEach { (key, value) -> if (this::constVar.isInitialized && key in constVar) { LoggerService.addErrorLine("Variable $key is read-only and cannot be modified.") errReadOnlyFlag = true } if (value.length >= PIPELINE_VARIABLES_STRING_LENGTH_MAX) { - LoggerService.addErrorLine("Variable $key value exceeds 4000 length limit.") + errLongValueVars.add(key) errLongValueFlag = true } if (!Pattern.matches(ENGLISH_NAME_PATTERN, key)) { - LoggerService.addErrorLine( - "Variable $key name is illegal,Variable names can only use letters, " + - "numbers and underscores, " + - "and the first character cannot start with a number" - ) + errChineseVars.add(key) errChineseVarName = true } } @@ -138,6 +137,7 @@ abstract class ITask { } if (this::dialect.isInitialized) { if (errLongValueFlag && !dialect.supportLongVarValue()) { + LoggerService.addWarnLine("Variable $errLongValueVars value exceeds 4000 length limit.") throw TaskExecuteException( errorMsg = "[Finish task] status: false, errorType: ${ErrorType.USER.num}, " + "errorCode: ${ErrorCode.USER_INPUT_INVAILD}," + @@ -147,6 +147,11 @@ abstract class ITask { ) } if (errChineseVarName && !dialect.supportChineseVarName()) { + LoggerService.addWarnLine( + "Variable $errChineseVars name is illegal,Variable names can only use letters, " + + "numbers and underscores, " + + "and the first character cannot start with a number" + ) throw TaskExecuteException( errorMsg = "[Finish task] status: false, errorType: ${ErrorType.USER.num}, " + "errorCode: ${ErrorCode.USER_INPUT_INVAILD}," + diff --git a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/market/MarketAtomTask.kt b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/market/MarketAtomTask.kt index a220bb1fbb8..a8fd681ffcb 100644 --- a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/market/MarketAtomTask.kt +++ b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/market/MarketAtomTask.kt @@ -506,7 +506,7 @@ open class MarketAtomTask : ITask() { atomParams[name] = EnvReplacementParser.parse( value = JsonUtil.toJson(value), contextMap = variables, - onlyExpression = true, + dialect = dialect, contextPair = customReplacement, functions = SpecialFunctions.functions, output = SpecialFunctions.output diff --git a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/script/ICommand.kt b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/script/ICommand.kt index ab8a34689b8..6be2d7876a1 100644 --- a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/script/ICommand.kt +++ b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/script/ICommand.kt @@ -88,7 +88,7 @@ interface ICommand { EnvReplacementParser.parse( value = command, contextMap = contextMap, - onlyExpression = true, + dialect = dialect, contextPair = EnvReplacementParser.getCustomExecutionContextByMap( variables = contextMap, extendNamedValueMap = listOf(