Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 触发器条件引入${{variables.xxx}}变量触发不了流水线 #10987 #10992

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import com.tencent.devops.process.pojo.PipelineNotifyTemplateEnum
import com.tencent.devops.process.pojo.webhook.PipelineWebhook
import com.tencent.devops.process.pojo.webhook.WebhookTriggerPipeline
import com.tencent.devops.process.service.scm.ScmProxyService
import com.tencent.devops.process.utils.PipelineVarUtil
import com.tencent.devops.repository.api.ServiceRepositoryResource
import com.tencent.devops.repository.pojo.Repository
import org.jooq.DSLContext
Expand Down Expand Up @@ -96,9 +97,11 @@ class PipelineWebhookService @Autowired constructor(
return
}
val triggerContainer = model.stages[0].containers[0] as TriggerContainer
val variables = triggerContainer.params.associate { param ->
param.id to param.defaultValue.toString()
}.toMutableMap()
val variables = PipelineVarUtil.fillVariableMap(
triggerContainer.params.associate { param ->
param.id to param.defaultValue.toString()
}
)
val elements = triggerContainer.elements.filterIsInstance<WebHookTriggerElement>()
val failedElementNames = mutableListOf<String>()
elements.forEach { element ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import com.tencent.devops.common.pipeline.utils.RepositoryConfigUtils
import com.tencent.devops.process.engine.dao.PipelineWebhookDao
import com.tencent.devops.process.pojo.webhook.PipelineWebhook
import com.tencent.devops.process.service.scm.ScmProxyService
import com.tencent.devops.process.utils.PipelineVarUtil
import com.tencent.devops.repository.api.ServiceRepositoryResource
import com.tencent.devops.repository.pojo.Repository
import org.jooq.DSLContext
Expand Down Expand Up @@ -337,9 +338,11 @@ class PipelineWebhookUpgradeService(
return
}
val triggerContainer = model.stages[0].containers[0] as TriggerContainer
val params = triggerContainer.params.associate { param ->
param.id to param.defaultValue.toString()
}
val params = PipelineVarUtil.fillVariableMap(
triggerContainer.params.associate { param ->
param.id to param.defaultValue.toString()
}
)
val elementMap =
triggerContainer.elements.filterIsInstance<WebHookTriggerElement>().associateBy { it.id }
val pipelineWebhooks = pipelineWebhookDao.listWebhook(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import com.tencent.devops.common.pipeline.utils.RepositoryConfigUtils
import com.tencent.devops.process.engine.dao.PipelineInfoDao
import com.tencent.devops.process.engine.dao.PipelineModelTaskDao
import com.tencent.devops.process.engine.dao.PipelineResourceDao
import com.tencent.devops.process.utils.PipelineVarUtil
import com.tencent.devops.repository.api.ServiceRepositoryResource
import com.tencent.devops.repository.pojo.RepoPipelineRefInfo
import com.tencent.devops.repository.pojo.RepoPipelineRefRequest
Expand Down Expand Up @@ -201,14 +202,16 @@ class RepoPipelineRefService @Autowired constructor(
channel: String
) {
val repoPipelineRefInfos = mutableListOf<RepoPipelineRefInfo>()
val variables = mutableMapOf<String, String>()
var variables = mutableMapOf<String, String>()
model?.stages?.forEachIndexed { index, stage ->
if (index == 0) {
val container = stage.containers[0] as TriggerContainer
// 解析变量
container.params.forEach { param ->
variables[param.id] = param.defaultValue.toString()
}
// 填充[variables.]前缀
variables = PipelineVarUtil.fillVariableMap(variables).toMutableMap()
analysisTriggerContainer(
projectId = projectId,
pipelineId = pipelineId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class PipelineBuildWebhookService @Autowired constructor(
return@elements
}
val webHookParams = WebhookElementParamsRegistrar.getService(element)
.getWebhookElementParams(element, variables) ?: return@elements
.getWebhookElementParams(element, PipelineVarUtil.fillVariableMap(variables)) ?: return@elements
val repositoryConfig = webHookParams.repositoryConfig
if (repositoryConfig.getRepositoryId().isBlank()) {
logger.info("repositoryHashId is blank for code trigger pipeline $pipelineId ")
Expand Down Expand Up @@ -419,7 +419,7 @@ class PipelineBuildWebhookService @Autowired constructor(
taskIds.forEach { taskId ->
val triggerElement = triggerElementMap[taskId] ?: return@forEach
val webHookParams = WebhookElementParamsRegistrar.getService(triggerElement)
.getWebhookElementParams(triggerElement, variables) ?: return@forEach
.getWebhookElementParams(triggerElement, PipelineVarUtil.fillVariableMap(variables)) ?: return@forEach
val repositoryConfig = webHookParams.repositoryConfig
if (repositoryConfig.repositoryHashId.isNullOrBlank() && repositoryConfig.repositoryName.isNullOrBlank()) {
logger.info("repositoryHashId is blank for code trigger pipeline $pipelineId ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import com.tencent.devops.process.pojo.pipeline.enums.PipelineYamlStatus
import com.tencent.devops.process.pojo.webhook.PipelineWebhookVersion
import com.tencent.devops.process.service.PipelineInfoFacadeService
import com.tencent.devops.process.service.view.PipelineViewGroupService
import com.tencent.devops.process.utils.PipelineVarUtil
import com.tencent.devops.process.yaml.actions.BaseAction
import com.tencent.devops.process.yaml.actions.GitActionCommon
import com.tencent.devops.process.yaml.actions.internal.PipelineYamlManualAction
Expand Down Expand Up @@ -704,9 +705,11 @@ class PipelineYamlRepositoryService @Autowired constructor(
return emptyList()
}
val triggerContainer = model.stages[0].containers[0] as TriggerContainer
val variables = triggerContainer.params.associate { param ->
param.id to param.defaultValue.toString()
}.toMutableMap()
val variables = PipelineVarUtil.fillVariableMap(
triggerContainer.params.associate { param ->
param.id to param.defaultValue.toString()
}
).toMutableMap()
// 补充yaml流水线代码库信息
variables[PIPELINE_PAC_REPO_HASH_ID] = repoHashId

Expand Down
Loading