Skip to content

Commit

Permalink
feat:流水线变量语法支持两种风格 #10576
Browse files Browse the repository at this point in the history
  • Loading branch information
mingshewhe committed Sep 29, 2024
1 parent 1cc8569 commit 525b136
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -254,6 +250,11 @@ class PipelineBuildService(
versionName = versionName,
yamlVersion = yamlVersion
)
// 校验流水线启动变量长度
checkBuildParameterLength(
pipelineDialect = pipelineDialectType.dialect,
buildParameters = context.buildParameters
)

val interceptResult = pipelineInterceptorChain.filter(
InterceptData(
Expand Down Expand Up @@ -430,14 +431,14 @@ class PipelineBuildService(
// return originStartParams
}

private fun checkBuildVariablesLength(
private fun checkBuildParameterLength(
pipelineDialect: IPipelineDialect,
startValues: Map<String, String>?
buildParameters: List<BuildParameters>
) {
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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -109,22 +110,20 @@ abstract class ITask {
protected fun addEnv(env: Map<String, String>) {
var errReadOnlyFlag = false
var errLongValueFlag = false
val errLongValueVars = mutableSetOf<String>()
var errChineseVarName = false
val errChineseVars = mutableSetOf<String>()
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
}
}
Expand All @@ -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}," +
Expand All @@ -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}," +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ interface ICommand {
EnvReplacementParser.parse(
value = command,
contextMap = contextMap,
onlyExpression = true,
dialect = dialect,
contextPair = EnvReplacementParser.getCustomExecutionContextByMap(
variables = contextMap,
extendNamedValueMap = listOf(
Expand Down

0 comments on commit 525b136

Please sign in to comment.