diff --git a/src/backend/ci/core/common/common-db-base/src/main/kotlin/com/tencent/devops/common/db/utils/JooqUtils.kt b/src/backend/ci/core/common/common-db-base/src/main/kotlin/com/tencent/devops/common/db/utils/JooqUtils.kt index 23c357d61a1..ef23fd7dd89 100644 --- a/src/backend/ci/core/common/common-db-base/src/main/kotlin/com/tencent/devops/common/db/utils/JooqUtils.kt +++ b/src/backend/ci/core/common/common-db-base/src/main/kotlin/com/tencent/devops/common/db/utils/JooqUtils.kt @@ -28,8 +28,6 @@ package com.tencent.devops.common.db.utils import com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException -import java.math.BigDecimal -import java.sql.Timestamp import org.jooq.DatePart import org.jooq.Field import org.jooq.Record @@ -37,16 +35,27 @@ import org.jooq.SelectOptionStep import org.jooq.SelectUnionStep import org.jooq.exception.DataAccessException import org.jooq.impl.DSL +import org.springframework.dao.DeadlockLoserDataAccessException +import java.math.BigDecimal +import java.sql.Timestamp object JooqUtils { const val JooqDeadLockMessage = "Deadlock found when trying to get lock; try restarting transaction" - fun retryWhenDeadLock(action: () -> T): T { + fun retryWhenDeadLock(retryTime: Int = 1, action: () -> T): T { return try { action() } catch (dae: DataAccessException) { - if (dae.isDeadLock()) action() else throw dae + if (retryTime - 1 < 0) { + throw dae + } + if (dae.isDeadLock()) retryWhenDeadLock(retryTime - 1, action) else throw dae + } catch (dae: DeadlockLoserDataAccessException) { + if (retryTime - 1 < 0) { + throw dae + } + retryWhenDeadLock(retryTime - 1, action) } } diff --git a/src/backend/ci/core/common/common-db-base/src/test/kotlin/com/tencent/devops/common/db/utils/JooqUtilsTest.kt b/src/backend/ci/core/common/common-db-base/src/test/kotlin/com/tencent/devops/common/db/utils/JooqUtilsTest.kt index 17e2b4b7f82..13612a47f0b 100644 --- a/src/backend/ci/core/common/common-db-base/src/test/kotlin/com/tencent/devops/common/db/utils/JooqUtilsTest.kt +++ b/src/backend/ci/core/common/common-db-base/src/test/kotlin/com/tencent/devops/common/db/utils/JooqUtilsTest.kt @@ -2,6 +2,7 @@ package com.tencent.devops.common.db.utils import org.jooq.exception.DataAccessException import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test class JooqUtilsTest { @@ -18,6 +19,19 @@ class JooqUtilsTest { Assertions.assertEquals(expect, actual) } + @Test + @DisplayName("重试多次") + fun retryWhenDeadLock_2() { + var actual = 0 + JooqUtils.retryWhenDeadLock(3) { + if (actual++ < 3) { + throw DataAccessException("mock sql dead lock; ${JooqUtils.JooqDeadLockMessage}") + } + } + val expect = 4 // retry + Assertions.assertEquals(expect, actual) + } + @Test fun assertThrowsRetryWhenDeadLock() { var actual = 0 diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/container/TriggerContainer.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/container/TriggerContainer.kt index 1a8ea378f51..ecfedd5642b 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/container/TriggerContainer.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/container/TriggerContainer.kt @@ -55,7 +55,7 @@ data class TriggerContainer( @get:Schema(title = "参数化构建", required = false) var params: List = listOf(), @get:Schema(title = "模板参数构建", required = false) - val templateParams: List? = null, + var templateParams: List? = null, @get:Schema(title = "构建版本号", required = false) var buildNo: BuildNo? = null, @get:Schema(title = diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GitlabWebhookElementParams.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GitlabWebhookElementParams.kt index 3e10a6bc755..93dcbb7b1ff 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GitlabWebhookElementParams.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GitlabWebhookElementParams.kt @@ -65,9 +65,6 @@ class GitlabWebhookElementParams : ScmWebhookElementParams?, @Parameter(description = "代码库URL", required = false) @QueryParam("materialUrl") materialUrl: String?, - @Parameter(description = "分支", required = false) + @Parameter(description = "源材料分支", required = false) @QueryParam("materialBranch") materialBranch: List?, - @Parameter(description = "commitId", required = false) + @Parameter(description = "源材料commitId", required = false) @QueryParam("materialCommitId") materialCommitId: String?, - @Parameter(description = "commitMessage", required = false) + @Parameter(description = "源材料commitMessage", required = false) @QueryParam("materialCommitMessage") materialCommitMessage: String?, @Parameter(description = "状态", required = false) @@ -296,7 +296,13 @@ interface ApigwBuildResourceV4 { startUser: List?, @Parameter(description = "是否查询归档数据", required = false) @QueryParam("archiveFlag") - archiveFlag: Boolean? = false + archiveFlag: Boolean? = false, + @Parameter(description = "触发代码库", required = false) + @QueryParam("triggerAlias") + triggerAlias: List? = null, + @Parameter(description = "触发分支", required = false) + @QueryParam("triggerBranch") + triggerBranch: List? = null ): Result> @Operation(summary = "获取流水线手动启动参数", tags = ["v4_app_build_startInfo", "v4_user_build_startInfo"]) diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt index 074d54d28b3..8d484cc457a 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt @@ -128,7 +128,9 @@ class ApigwBuildResourceV4Impl @Autowired constructor( buildNoEnd: Int?, buildMsg: String?, startUser: List?, - archiveFlag: Boolean? + archiveFlag: Boolean?, + triggerAlias: List?, + triggerBranch: List? ): Result> { logger.info( "OPENAPI_BUILD_V4|$userId|get history build|$projectId|$pipelineId|$page|$pageSize" + @@ -165,7 +167,9 @@ class ApigwBuildResourceV4Impl @Autowired constructor( buildNoEnd = buildNoEnd, buildMsg = buildMsg, startUser = startUser, - archiveFlag = archiveFlag + archiveFlag = archiveFlag, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) } diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/app/AppPipelineBuildResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/app/AppPipelineBuildResource.kt index 99f0888e629..34c467360c6 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/app/AppPipelineBuildResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/app/AppPipelineBuildResource.kt @@ -347,6 +347,12 @@ interface AppPipelineBuildResource { buildMsg: String?, @Parameter(description = "查看指定版本调试数据", required = false, example = "false") @QueryParam("version") - customVersion: Int? = null + customVersion: Int? = null, + @Parameter(description = "触发代码库", required = false) + @QueryParam("triggerAlias") + triggerAlias: List?, + @Parameter(description = "触发分支", required = false) + @QueryParam("triggerBranch") + triggerBranch: List? ): Result> } diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceBuildResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceBuildResource.kt index 7b22149b9c5..18d6be05fca 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceBuildResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceBuildResource.kt @@ -504,7 +504,13 @@ interface ServiceBuildResource { archiveFlag: Boolean? = false, @Parameter(description = "查看指定版本调试数据", required = false, example = "false") @QueryParam("version") - customVersion: Int? = null + customVersion: Int? = null, + @Parameter(description = "触发代码库", required = false) + @QueryParam("triggerAlias") + triggerAlias: List? = null, + @Parameter(description = "触发分支", required = false) + @QueryParam("triggerBranch") + triggerBranch: List? = null ): Result> @Operation(summary = "获取构建详情") diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserBuildResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserBuildResource.kt index 6a744d74b60..834f9122939 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserBuildResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserBuildResource.kt @@ -38,6 +38,7 @@ import com.tencent.devops.common.pipeline.pojo.BuildParameters import com.tencent.devops.common.pipeline.pojo.StageReviewRequest import com.tencent.devops.common.pipeline.pojo.element.Element import com.tencent.devops.common.web.annotation.BkField +import com.tencent.devops.process.enums.HistorySearchType import com.tencent.devops.process.pojo.BuildHistory import com.tencent.devops.process.pojo.BuildHistoryRemark import com.tencent.devops.process.pojo.BuildId @@ -400,13 +401,13 @@ interface UserBuildResource { @Parameter(description = "每页多少条", required = false, example = "20") @QueryParam("pageSize") pageSize: Int?, - @Parameter(description = "代码库别名", required = false) + @Parameter(description = "源材料代码库别名", required = false) @QueryParam("materialAlias") materialAlias: List?, @Parameter(description = "代码库URL", required = false) @QueryParam("materialUrl") materialUrl: String?, - @Parameter(description = "分支", required = false) + @Parameter(description = "源材料分支", required = false) @QueryParam("materialBranch") materialBranch: List?, @Parameter(description = "commitId", required = false) @@ -462,7 +463,13 @@ interface UserBuildResource { archiveFlag: Boolean? = false, @Parameter(description = "查看指定版本调试数据", required = false, example = "false") @QueryParam("version") - customVersion: Int? = null + customVersion: Int? = null, + @Parameter(description = "触发代码库", required = false) + @QueryParam("triggerAlias") + triggerAlias: List?, + @Parameter(description = "触发分支", required = false) + @QueryParam("triggerBranch") + triggerBranch: List? ): Result> @Operation(summary = "修改流水线备注") @@ -534,7 +541,13 @@ interface UserBuildResource { pipelineId: String, @Parameter(description = "查看指定版本调试数据", required = false, example = "false") @QueryParam("version") - debugVersion: Int? = null + debugVersion: Int? = null, + @Parameter(description = "搜索分支关键字", required = false) + @QueryParam("search") + search: String?, + @Parameter(description = "搜索类型, 触发/源材料", required = false) + @QueryParam("type") + type: HistorySearchType? ): Result> @Operation(summary = "获取流水线构建中的查询条件-分支") @@ -556,7 +569,13 @@ interface UserBuildResource { alias: List?, @Parameter(description = "查看指定版本调试数据", required = false, example = "false") @QueryParam("debugVersion") - debugVersion: Int? = null + debugVersion: Int? = null, + @Parameter(description = "搜索分支关键字", required = false) + @QueryParam("search") + search: String?, + @Parameter(description = "搜索类型,触发/源材料", required = false) + @QueryParam("type") + type: HistorySearchType? ): Result> @Operation(summary = "触发审核") diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/enums/HistorySearchType.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/enums/HistorySearchType.kt new file mode 100644 index 00000000000..10e00ed6517 --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/enums/HistorySearchType.kt @@ -0,0 +1,39 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.devops.process.enums + +/** + * 构建历史搜索类型 + */ +enum class HistorySearchType { + // 触发器 + TRIGGER, + + // 源材料 + MATERIAL +} diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/PipelineDetail.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/PipelineDetail.kt index 98e08b733c1..b689006e170 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/PipelineDetail.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/PipelineDetail.kt @@ -51,6 +51,8 @@ data class PipelineDetail( val instanceFromTemplate: Boolean, @get:Schema(title = "当前模板的ID", required = false) var templateId: String?, + @get:Schema(title = "关联模板版本", required = false) + var templateVersion: Long?, @get:Schema(title = "草稿或最新的发布版本") val version: Int, @get:Schema(title = "草稿或最新的发布版本名称") diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt index 211a783230e..8c6e707546e 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt @@ -49,13 +49,11 @@ import com.tencent.devops.model.process.tables.records.TPipelineBuildHistoryReco import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.engine.pojo.BuildInfo import com.tencent.devops.process.engine.pojo.BuildRetryInfo +import com.tencent.devops.process.enums.HistorySearchType import com.tencent.devops.process.pojo.BuildStageStatus import com.tencent.devops.process.pojo.PipelineBuildMaterial import com.tencent.devops.process.pojo.app.StartBuildContext import com.tencent.devops.process.pojo.code.WebhookInfo -import java.sql.Timestamp -import java.time.LocalDateTime -import javax.ws.rs.core.Response import org.jooq.Condition import org.jooq.DSLContext import org.jooq.DatePart @@ -64,6 +62,9 @@ import org.jooq.RecordMapper import org.jooq.SelectConditionStep import org.jooq.impl.DSL import org.springframework.stereotype.Repository +import java.sql.Timestamp +import java.time.LocalDateTime +import javax.ws.rs.core.Response @Suppress("ALL") @Repository @@ -72,7 +73,7 @@ class PipelineBuildDao { companion object { private val mapper = PipelineBuildInfoJooqMapper() private val debugMapper = PipelineDebugBuildInfoJooqMapper() - private const val DEFAULT_PAGE_SIZE = 10 + private const val DEFAULT_PAGE_SIZE = 50 } fun create(dslContext: DSLContext, startBuildContext: StartBuildContext) { @@ -956,7 +957,9 @@ class PipelineBuildDao { buildNoEnd: Int?, buildMsg: String?, startUser: List?, - debugVersion: Int? + debugVersion: Int?, + triggerAlias: List?, + triggerBranch: List? ): Int { return if (debugVersion == null) { with(T_PIPELINE_BUILD_HISTORY) { @@ -983,7 +986,9 @@ class PipelineBuildDao { remark = remark, buildNoStart = buildNoStart, buildNoEnd = buildNoEnd, - buildMsg = buildMsg + buildMsg = buildMsg, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) where.fetchOne(0, Int::class.java)!! } @@ -1014,7 +1019,9 @@ class PipelineBuildDao { remark = remark, buildNoStart = buildNoStart, buildNoEnd = buildNoEnd, - buildMsg = buildMsg + buildMsg = buildMsg, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) where.fetchOne(0, Int::class.java)!! } @@ -1048,7 +1055,9 @@ class PipelineBuildDao { buildMsg: String?, startUser: List?, updateTimeDesc: Boolean? = null, - debugVersion: Int? + debugVersion: Int?, + triggerAlias: List?, + triggerBranch: List? ): Collection { return if (debugVersion == null) { with(T_PIPELINE_BUILD_HISTORY) { @@ -1074,7 +1083,9 @@ class PipelineBuildDao { remark = remark, buildNoStart = buildNoStart, buildNoEnd = buildNoEnd, - buildMsg = buildMsg + buildMsg = buildMsg, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) when (updateTimeDesc) { @@ -1111,7 +1122,9 @@ class PipelineBuildDao { remark = remark, buildNoStart = buildNoStart, buildNoEnd = buildNoEnd, - buildMsg = buildMsg + buildMsg = buildMsg, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) when (updateTimeDesc) { true -> where.orderBy(UPDATE_TIME.desc(), BUILD_ID) @@ -1145,7 +1158,9 @@ class PipelineBuildDao { remark: String?, buildNoStart: Int?, buildNoEnd: Int?, - buildMsg: String? + buildMsg: String?, + triggerAlias: List?, + triggerBranch: List? ) { if (!materialAlias.isNullOrEmpty() && materialAlias.first().isNotBlank()) { var conditionsOr: Condition @@ -1243,6 +1258,36 @@ class PipelineBuildDao { if (!buildMsg.isNullOrBlank()) { where.and(BUILD_MSG.like("%$buildMsg%")) } + if (!triggerAlias.isNullOrEmpty() && triggerAlias.first().isNotBlank()) { + var conditionsOr: Condition + + conditionsOr = JooqUtils.jsonExtract(t1 = WEBHOOK_INFO, t2 = "\$.webhookAliasName", lower = true) + .like("%${triggerAlias.first().lowercase()}%") + + triggerAlias.forEachIndexed { index, s -> + if (index == 0) return@forEachIndexed + conditionsOr = conditionsOr.or( + JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookAliasName", lower = true) + .like("%${s.lowercase()}%") + ) + } + where.and(conditionsOr) + } + if (!triggerBranch.isNullOrEmpty() && triggerBranch.first().isNotBlank()) { + var conditionsOr: Condition + + conditionsOr = JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookBranch", lower = true) + .like("%${triggerBranch.first().lowercase()}%") + + triggerBranch.forEachIndexed { index, s -> + if (index == 0) return@forEachIndexed + conditionsOr = conditionsOr.or( + JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookBranch", lower = true) + .like("%${s.lowercase()}%") + ) + } + where.and(conditionsOr) + } } private fun TPipelineBuildHistoryDebug.makeDebugCondition( @@ -1266,7 +1311,9 @@ class PipelineBuildDao { remark: String?, buildNoStart: Int?, buildNoEnd: Int?, - buildMsg: String? + buildMsg: String?, + triggerAlias: List?, + triggerBranch: List? ) { // 增加过滤,对前端屏蔽已删除的构建 where.and(DELETE_TIME.isNull) @@ -1366,6 +1413,36 @@ class PipelineBuildDao { if (!buildMsg.isNullOrBlank()) { where.and(BUILD_MSG.like("%$buildMsg%")) } + if (!triggerAlias.isNullOrEmpty() && triggerAlias.first().isNotBlank()) { + var conditionsOr: Condition + + conditionsOr = JooqUtils.jsonExtract(t1 = WEBHOOK_INFO, t2 = "\$.webhookAliasName", lower = true) + .like("%${triggerAlias.first().lowercase()}%") + + triggerAlias.forEachIndexed { index, s -> + if (index == 0) return@forEachIndexed + conditionsOr = conditionsOr.or( + JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookAliasName", lower = true) + .like("%${s.lowercase()}%") + ) + } + where.and(conditionsOr) + } + if (!triggerBranch.isNullOrEmpty() && triggerBranch.first().isNotBlank()) { + var conditionsOr: Condition + + conditionsOr = JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookBranch", lower = true) + .like("%${triggerBranch.first().lowercase()}%") + + triggerBranch.forEachIndexed { index, s -> + if (index == 0) return@forEachIndexed + conditionsOr = conditionsOr.or( + JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookBranch", lower = true) + .like("%${s.lowercase()}%") + ) + } + where.and(conditionsOr) + } } fun updateBuildRemark( @@ -1410,25 +1487,43 @@ class PipelineBuildDao { } } - fun getBuildHistoryMaterial( + /** + * 构建历史搜索下拉框 + */ + fun listHistorySearchOptions( dslContext: DSLContext, projectId: String, pipelineId: String, - debugVersion: Int? + debugVersion: Int?, + type: HistorySearchType ): Collection { return if (debugVersion == null) { with(T_PIPELINE_BUILD_HISTORY) { - dslContext.selectFrom(this) + val where = dslContext.selectFrom(this) .where(PIPELINE_ID.eq(pipelineId).and(PROJECT_ID.eq(projectId))) - .orderBy(BUILD_NUM.desc()).limit(DEFAULT_PAGE_SIZE) + when (type) { + HistorySearchType.MATERIAL -> + where.and(MATERIAL.isNotNull) + + HistorySearchType.TRIGGER -> + where.and(WEBHOOK_INFO.isNotNull) + } + where.orderBy(BUILD_NUM.desc()).limit(DEFAULT_PAGE_SIZE) .fetch(mapper) } } else { with(T_PIPELINE_BUILD_HISTORY_DEBUG) { - dslContext.selectFrom(this) + val where = dslContext.selectFrom(this) .where(PIPELINE_ID.eq(pipelineId).and(PROJECT_ID.eq(projectId))) .and(VERSION.eq(debugVersion)) - .orderBy(BUILD_NUM.desc()).limit(DEFAULT_PAGE_SIZE) + when (type) { + HistorySearchType.MATERIAL -> + where.and(MATERIAL.isNotNull) + + HistorySearchType.TRIGGER -> + where.and(WEBHOOK_INFO.isNotNull) + } + where.orderBy(BUILD_NUM.desc()).limit(DEFAULT_PAGE_SIZE) .fetch(debugMapper) } } diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt index 5e012887f1e..9a6509046a8 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt @@ -287,27 +287,29 @@ class PipelineRepositoryService constructor( ) result } else { - val result = create( - projectId = projectId, - pipelineId = pipelineId, - model = model, - customSetting = setting, - yaml = yaml, - userId = userId, - channelCode = channelCode, - canManualStartup = canManualStartup, - canElementSkip = canElementSkip, - buildNo = buildNo, - modelTasks = modelTasks, - useSubscriptionSettings = useSubscriptionSettings, - useLabelSettings = useLabelSettings, - useConcurrencyGroup = useConcurrencyGroup, - templateId = templateId, - versionStatus = versionStatus, - branchName = branchName, - description = description, - baseVersion = baseVersion - ) + val result = JooqUtils.retryWhenDeadLock(3) { + create( + projectId = projectId, + pipelineId = pipelineId, + model = model, + customSetting = setting, + yaml = yaml, + userId = userId, + channelCode = channelCode, + canManualStartup = canManualStartup, + canElementSkip = canElementSkip, + buildNo = buildNo, + modelTasks = modelTasks, + useSubscriptionSettings = useSubscriptionSettings, + useLabelSettings = useLabelSettings, + useConcurrencyGroup = useConcurrencyGroup, + templateId = templateId, + versionStatus = versionStatus, + branchName = branchName, + description = description, + baseVersion = baseVersion + ) + } operationLogService.addOperationLog( userId = userId, projectId = projectId, @@ -735,18 +737,14 @@ class PipelineRepositoryService constructor( newSetting = setting } // 如果不需要覆盖模板内容,则直接保存传值或默认值 - JooqUtils.retryWhenDeadLock { - pipelineSettingDao.saveSetting(transactionContext, newSetting) - } - JooqUtils.retryWhenDeadLock { - pipelineSettingVersionDao.saveSetting( - dslContext = transactionContext, - setting = newSetting, - id = client.get(ServiceAllocIdResource::class) - .generateSegmentId(PIPELINE_SETTING_VERSION_BIZ_TAG_NAME).data, - version = settingVersion - ) - } + pipelineSettingDao.saveSetting(transactionContext, newSetting) + pipelineSettingVersionDao.saveSetting( + dslContext = transactionContext, + setting = newSetting, + id = client.get(ServiceAllocIdResource::class) + .generateSegmentId(PIPELINE_SETTING_VERSION_BIZ_TAG_NAME).data, + version = settingVersion + ) } else { pipelineSettingDao.updateSetting( dslContext = transactionContext, @@ -755,16 +753,14 @@ class PipelineRepositoryService constructor( name = model.name, desc = model.desc ?: "" )?.let { setting -> - JooqUtils.retryWhenDeadLock { - pipelineSettingVersionDao.saveSetting( - dslContext = transactionContext, - setting = setting, - id = client.get(ServiceAllocIdResource::class) - .generateSegmentId(PIPELINE_SETTING_VERSION_BIZ_TAG_NAME) - .data, - version = settingVersion - ) - } + pipelineSettingVersionDao.saveSetting( + dslContext = transactionContext, + setting = setting, + id = client.get(ServiceAllocIdResource::class) + .generateSegmentId(PIPELINE_SETTING_VERSION_BIZ_TAG_NAME) + .data, + version = settingVersion + ) newSetting = setting } } @@ -1711,6 +1707,28 @@ class PipelineRepositoryService constructor( ) } + return JooqUtils.retryWhenDeadLock(3) { + transactionSaveSetting( + context = context, + setting = setting, + versionStatus = versionStatus, + userId = userId, + updateLastModifyUser = updateLastModifyUser, + version = version, + isTemplate = isTemplate + ) + } + } + + private fun transactionSaveSetting( + context: DSLContext?, + setting: PipelineSetting, + versionStatus: VersionStatus, + userId: String, + updateLastModifyUser: Boolean?, + version: Int, + isTemplate: Boolean + ): PipelineName { var oldName: String = setting.pipelineName (context ?: dslContext).transaction { t -> val transactionContext = DSL.using(t) @@ -1743,19 +1761,17 @@ class PipelineRepositoryService constructor( maxPipelineResNum = old.maxPipelineResNum ) } - JooqUtils.retryWhenDeadLock { - pipelineSettingVersionDao.saveSetting( - dslContext = transactionContext, - setting = setting, - version = version, - isTemplate = isTemplate, - id = client.get(ServiceAllocIdResource::class).generateSegmentId( - PIPELINE_SETTING_VERSION_BIZ_TAG_NAME - ).data - ) - } + pipelineSettingVersionDao.saveSetting( + dslContext = transactionContext, + setting = setting, + version = version, + isTemplate = isTemplate, + id = client.get(ServiceAllocIdResource::class).generateSegmentId( + PIPELINE_SETTING_VERSION_BIZ_TAG_NAME + ).data + ) } - if (versionStatus.isReleasing()) JooqUtils.retryWhenDeadLock { + if (versionStatus.isReleasing()) { pipelineSettingDao.saveSetting( transactionContext, setting, isTemplate ) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt index 6d97ed88e11..86a80d22fe2 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt @@ -106,6 +106,7 @@ import com.tencent.devops.process.engine.service.record.TaskBuildRecordService import com.tencent.devops.process.engine.service.rule.PipelineRuleService import com.tencent.devops.process.engine.utils.ContainerUtils import com.tencent.devops.process.engine.utils.PipelineUtils +import com.tencent.devops.process.enums.HistorySearchType import com.tencent.devops.process.pojo.BuildBasicInfo import com.tencent.devops.process.pojo.BuildHistory import com.tencent.devops.process.pojo.BuildId @@ -136,15 +137,15 @@ import com.tencent.devops.process.utils.PIPELINE_NAME import com.tencent.devops.process.utils.PIPELINE_RETRY_COUNT import com.tencent.devops.process.utils.PIPELINE_START_TASK_ID import com.tencent.devops.process.utils.PipelineVarUtil -import java.time.LocalDateTime -import java.util.Date -import java.util.concurrent.TimeUnit import org.jooq.DSLContext import org.jooq.Result import org.jooq.impl.DSL import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service +import java.time.LocalDateTime +import java.util.Date +import java.util.concurrent.TimeUnit /** * 流水线运行时相关的服务 @@ -371,7 +372,9 @@ class PipelineRuntimeService @Autowired constructor( startUser: List?, updateTimeDesc: Boolean? = null, queryDslContext: DSLContext? = null, - debugVersion: Int? + debugVersion: Int?, + triggerAlias: List?, + triggerBranch: List? ): List { val currentTimestamp = System.currentTimeMillis() // 限制最大一次拉1000,防止攻击 @@ -404,7 +407,9 @@ class PipelineRuntimeService @Autowired constructor( buildMsg = buildMsg, startUser = startUser, updateTimeDesc = updateTimeDesc, - debugVersion = debugVersion + debugVersion = debugVersion, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) val result = mutableListOf() list.forEach { @@ -417,43 +422,124 @@ class PipelineRuntimeService @Autowired constructor( pipelineBuildDao.updateBuildRemark(dslContext, projectId, pipelineId, buildId, remark) } - fun getHistoryConditionRepo(projectId: String, pipelineId: String, debugVersion: Int?): List { - val history = pipelineBuildDao.getBuildHistoryMaterial(dslContext, projectId, pipelineId, debugVersion) - val materialObjList = mutableListOf() - history.forEach { - if (!it.material.isNullOrEmpty()) { - materialObjList.addAll(it.material!!) + fun getHistoryConditionRepo( + projectId: String, + pipelineId: String, + debugVersion: Int?, + search: String?, + type: HistorySearchType? = HistorySearchType.MATERIAL + ): List { + val aliasNames = when (type) { + HistorySearchType.MATERIAL -> { + val history = pipelineBuildDao.listHistorySearchOptions( + dslContext = dslContext, + projectId = projectId, + pipelineId = pipelineId, + debugVersion = debugVersion, + type = type + ) + val materialObjList = mutableListOf() + history.forEach { + if (!it.material.isNullOrEmpty()) { + materialObjList.addAll(it.material!!) + } + } + materialObjList.filter { !it.aliasName.isNullOrBlank() } + .map { it.aliasName!! } + .distinct() } + + HistorySearchType.TRIGGER -> { + val history = pipelineBuildDao.listHistorySearchOptions( + dslContext = dslContext, + projectId = projectId, + pipelineId = pipelineId, + debugVersion = debugVersion, + type = type + ) + history.filter { it.webhookInfo != null && !it.webhookInfo!!.webhookAliasName.isNullOrBlank() } + .map { it.webhookInfo!!.webhookAliasName!! } + .distinct() + } + + else -> emptyList() + } + return if (search.isNullOrBlank()) { + aliasNames + } else { + aliasNames.filter { it.contains(search) } } - return materialObjList.filter { !it.aliasName.isNullOrBlank() }.map { it.aliasName!! }.distinct() } fun getHistoryConditionBranch( projectId: String, pipelineId: String, aliasList: List?, - debugVersion: Int? = null + debugVersion: Int? = null, + search: String?, + type: HistorySearchType? = HistorySearchType.MATERIAL ): List { - val history = pipelineBuildDao.getBuildHistoryMaterial(dslContext, projectId, pipelineId, debugVersion) - val materialObjList = mutableListOf() - history.forEach { - if (!it.material.isNullOrEmpty()) { - materialObjList.addAll(it.material!!) + val branchNames = when (type) { + HistorySearchType.MATERIAL -> { + val history = pipelineBuildDao.listHistorySearchOptions( + dslContext = dslContext, + projectId = projectId, + pipelineId = pipelineId, + debugVersion = debugVersion, + type = type + ) + val materialObjList = mutableListOf() + history.forEach { + if (!it.material.isNullOrEmpty()) { + materialObjList.addAll(it.material!!) + } + } + val aliasNames = if (!aliasList.isNullOrEmpty() && aliasList.first().isNotBlank()) { + aliasList + } else { + materialObjList.map { it.aliasName } + } + + val result = mutableListOf() + aliasNames.distinct().forEach { alias -> + val branchNames = materialObjList.filter { + it.aliasName == alias && !it.branchName.isNullOrBlank() + }.map { it.branchName!! }.distinct() + result.addAll(branchNames) + } + result.distinct() } + + HistorySearchType.TRIGGER -> { + val history = pipelineBuildDao.listHistorySearchOptions( + dslContext = dslContext, + projectId = projectId, + pipelineId = pipelineId, + debugVersion = debugVersion, + type = type + ) + val webhookInfoList = history.filter { it.webhookInfo != null }.map { it.webhookInfo!! } + val aliasNames = if (!aliasList.isNullOrEmpty() && aliasList.first().isNotBlank()) { + aliasList + } else { + webhookInfoList.map { it.webhookAliasName } + } + val result = mutableListOf() + aliasNames.distinct().forEach { alias -> + val branchNames = webhookInfoList.filter { + it.webhookAliasName == alias && !it.webhookBranch.isNullOrBlank() + }.map { it.webhookBranch!! }.distinct() + result.addAll(branchNames) + } + result.distinct() + } + else -> emptyList() } - val aliasNames = if (aliasList.isNullOrEmpty()) { - materialObjList.map { it.aliasName } + return if (search.isNullOrBlank()) { + branchNames } else { - aliasList - } - - val result = mutableListOf() - aliasNames.distinct().forEach { alias -> - val branchNames = materialObjList.filter { it.aliasName == alias && !it.branchName.isNullOrBlank() } - .map { it.branchName!! }.distinct() - result.addAll(branchNames) + branchNames.filter { it.contains(search) } } - return result.distinct() } private fun genBuildHistory( @@ -1792,7 +1878,9 @@ class PipelineRuntimeService @Autowired constructor( buildMsg: String? = null, startUser: List? = null, queryDslContext: DSLContext? = null, - debugVersion: Int? = null + debugVersion: Int? = null, + triggerAlias: List?, + triggerBranch: List? ): Int { return pipelineBuildDao.count( dslContext = queryDslContext ?: dslContext, @@ -1818,7 +1906,9 @@ class PipelineRuntimeService @Autowired constructor( buildNoEnd = buildNoEnd, buildMsg = buildMsg, startUser = startUser, - debugVersion = debugVersion + debugVersion = debugVersion, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) } diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/utils/PipelineUtils.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/utils/PipelineUtils.kt index d8b8c27fbba..062c79a5358 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/utils/PipelineUtils.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/utils/PipelineUtils.kt @@ -158,6 +158,39 @@ object PipelineUtils { return stages } + /** + * 将流水线常量转换成模板常量 + */ + fun fixedTemplateParam(model: Model): Model { + val triggerContainer = model.stages[0].containers[0] as TriggerContainer + val params = mutableListOf() + val templateParams = mutableListOf() + triggerContainer.params.forEach { + if (it.constant == true) { + templateParams.add(it) + } else { + params.add(it) + } + } + val fixedTriggerContainer = triggerContainer.copy( + params = params, + templateParams = if (templateParams.isEmpty()) { + null + } else { + templateParams + } + ) + val stages = ArrayList() + model.stages.forEachIndexed { index, stage -> + if (index == 0) { + stages.add(stage.copy(containers = listOf(fixedTriggerContainer))) + } else { + stages.add(stage) + } + } + return model.copy(stages = stages) + } + /** * 通过流水线参数和模板编排生成新Model */ @@ -178,7 +211,9 @@ object PipelineUtils { BuildPropertyCompatibilityTools.mergeProperties( from = templateTrigger.params, to = BuildPropertyCompatibilityTools.mergeProperties( - from = templateTrigger.templateParams!!, to = param ?: emptyList() + // 模板常量需要变成流水线常量 + from = templateTrigger.templateParams!!.map { it.copy(constant = true) }, + to = param ?: emptyList() ) ) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt index 70f6091c997..4502e8b1f50 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt @@ -385,7 +385,9 @@ class ServiceBuildResourceImpl @Autowired constructor( buildMsg: String?, startUser: List?, archiveFlag: Boolean?, - customVersion: Int? + customVersion: Int?, + triggerAlias: List?, + triggerBranch: List? ): Result> { checkUserId(userId) checkParam(projectId, pipelineId) @@ -419,7 +421,9 @@ class ServiceBuildResourceImpl @Autowired constructor( startUser = startUser?.filter { it.isNotBlank() }, updateTimeDesc = updateTimeDesc, archiveFlag = archiveFlag, - customVersion = customVersion + customVersion = customVersion, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) return Result(result) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt index b3f5d17faeb..8c4585739c7 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt @@ -42,6 +42,7 @@ import com.tencent.devops.common.pipeline.pojo.element.Element import com.tencent.devops.common.web.RestResource import com.tencent.devops.process.api.user.UserBuildResource import com.tencent.devops.process.engine.service.PipelineProgressRateService +import com.tencent.devops.process.enums.HistorySearchType import com.tencent.devops.process.pojo.BuildHistory import com.tencent.devops.process.pojo.BuildHistoryRemark import com.tencent.devops.process.pojo.BuildId @@ -450,7 +451,9 @@ class UserBuildResourceImpl @Autowired constructor( buildNoEnd: Int?, buildMsg: String?, archiveFlag: Boolean?, - customVersion: Int? + customVersion: Int?, + triggerAlias: List?, + triggerBranch: List? ): Result> { checkParam(userId, projectId, pipelineId) val result = pipelineBuildFacadeService.getHistoryBuild( @@ -479,7 +482,9 @@ class UserBuildResourceImpl @Autowired constructor( buildNoEnd = buildNoEnd, buildMsg = buildMsg, archiveFlag = archiveFlag, - customVersion = customVersion + customVersion = customVersion, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) if (archiveFlag != true) { pipelineRecentUseService.record(userId, projectId, pipelineId) @@ -527,12 +532,21 @@ class UserBuildResourceImpl @Autowired constructor( userId: String, projectId: String, pipelineId: String, - debugVersion: Int? + debugVersion: Int?, + search: String?, + type: HistorySearchType? ): Result> { checkParam(userId, projectId, pipelineId) - return Result(pipelineBuildFacadeService.getHistoryConditionRepo( - userId, projectId, pipelineId, debugVersion - )) + return Result( + pipelineBuildFacadeService.getHistoryConditionRepo( + userId = userId, + projectId = projectId, + pipelineId = pipelineId, + debugVersion = debugVersion, + search = search, + type = type + ) + ) } override fun getHistoryConditionBranch( @@ -540,7 +554,9 @@ class UserBuildResourceImpl @Autowired constructor( projectId: String, pipelineId: String, alias: List?, - debugVersion: Int? + debugVersion: Int?, + search: String?, + type: HistorySearchType? ): Result> { checkParam(userId, projectId, pipelineId) return Result( @@ -549,7 +565,9 @@ class UserBuildResourceImpl @Autowired constructor( projectId = projectId, pipelineId = pipelineId, alias = alias, - debugVersion = debugVersion + debugVersion = debugVersion, + search = search, + type = type ) ) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/app/AppPipelineBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/app/AppPipelineBuildResourceImpl.kt index 4bde9b93f38..55ff59ccf21 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/app/AppPipelineBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/app/AppPipelineBuildResourceImpl.kt @@ -198,7 +198,9 @@ class AppPipelineBuildResourceImpl @Autowired constructor( buildNoStart: Int?, buildNoEnd: Int?, buildMsg: String?, - customVersion: Int? + customVersion: Int?, + triggerAlias: List?, + triggerBranch: List? ): Result> { checkParam(userId, projectId, pipelineId, pageSize) val result = pipelineBuildFacadeService.getHistoryBuild( @@ -226,7 +228,9 @@ class AppPipelineBuildResourceImpl @Autowired constructor( buildNoStart = buildNoStart, buildNoEnd = buildNoEnd, buildMsg = buildMsg, - customVersion = customVersion + customVersion = customVersion, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) return Result(result) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineVersionFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineVersionFacadeService.kt index f2272a07d26..4a00709c108 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineVersionFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineVersionFacadeService.kt @@ -196,6 +196,7 @@ class PipelineVersionFacadeService @Autowired constructor( hasCollect = detailInfo.hasCollect, instanceFromTemplate = detailInfo.instanceFromTemplate, templateId = detailInfo.templateId, + templateVersion = detailInfo.templateVersion, canManualStartup = detailInfo.canManualStartup, canDebug = canDebug, canRelease = canRelease, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt index d65c55e9a1f..e416199294a 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt @@ -102,6 +102,7 @@ import com.tencent.devops.process.engine.service.record.ContainerBuildRecordServ import com.tencent.devops.process.engine.service.record.PipelineBuildRecordService import com.tencent.devops.process.engine.utils.BuildUtils import com.tencent.devops.process.engine.utils.PipelineUtils +import com.tencent.devops.process.enums.HistorySearchType import com.tencent.devops.process.jmx.api.ProcessJmxApi import com.tencent.devops.process.permission.PipelinePermissionService import com.tencent.devops.process.pojo.BuildBasicInfo @@ -671,7 +672,6 @@ class PipelineBuildFacadeService( ) // 如果是PAC流水线,需要加上代码库hashId,给checkout:self使用 pipelineYamlFacadeService.buildYamlManualParamMap( - userId = userId, projectId = projectId, pipelineId = pipelineId )?.let { @@ -1965,7 +1965,9 @@ class PipelineBuildFacadeService( startUser: List? = null, updateTimeDesc: Boolean? = null, archiveFlag: Boolean? = false, - customVersion: Int? + customVersion: Int?, + triggerAlias: List?, + triggerBranch: List? ): BuildHistoryPage { val pageNotNull = page ?: 0 val pageSizeNotNull = pageSize ?: 50 @@ -2045,7 +2047,9 @@ class PipelineBuildFacadeService( buildMsg = buildMsg, startUser = startUser, queryDslContext = queryDslContext, - debugVersion = targetDebugVersion + debugVersion = targetDebugVersion, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) val newHistoryBuilds = pipelineRuntimeService.listPipelineBuildHistory( @@ -2075,7 +2079,9 @@ class PipelineBuildFacadeService( startUser = startUser, updateTimeDesc = updateTimeDesc, queryDslContext = queryDslContext, - debugVersion = targetDebugVersion + debugVersion = targetDebugVersion, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) val buildHistories = mutableListOf() buildHistories.addAll(newHistoryBuilds) @@ -2157,7 +2163,9 @@ class PipelineBuildFacadeService( userId: String, projectId: String, pipelineId: String, - debugVersion: Int? + debugVersion: Int?, + search: String?, + type: HistorySearchType? ): List { pipelinePermissionService.validPipelinePermission( userId = userId, @@ -2175,7 +2183,13 @@ class PipelineBuildFacadeService( val draftVersion = pipelineRepositoryService.getDraftVersionResource(projectId, pipelineId) draftVersion?.version == debugVersion } - return pipelineRuntimeService.getHistoryConditionRepo(projectId, pipelineId, targetDebugVersion) + return pipelineRuntimeService.getHistoryConditionRepo( + projectId = projectId, + pipelineId = pipelineId, + debugVersion = targetDebugVersion, + search = search, + type = type + ) } fun getHistoryConditionBranch( @@ -2183,7 +2197,9 @@ class PipelineBuildFacadeService( projectId: String, pipelineId: String, alias: List?, - debugVersion: Int? + debugVersion: Int?, + search: String?, + type: HistorySearchType? ): List { pipelinePermissionService.validPipelinePermission( userId = userId, @@ -2202,7 +2218,12 @@ class PipelineBuildFacadeService( draftVersion?.version == debugVersion } return pipelineRuntimeService.getHistoryConditionBranch( - projectId, pipelineId, alias, targetDebugVersion + projectId = projectId, + pipelineId = pipelineId, + aliasList = alias, + debugVersion = targetDebugVersion, + search = search, + type = type ) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt index da357044710..e7bb18cd178 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt @@ -369,7 +369,7 @@ class TemplateFacadeService @Autowired constructor( statusCode = Response.Status.NOT_FOUND.statusCode, errorCode = ProcessMessageCode.ERROR_PIPELINE_MODEL_NOT_EXISTS ) - val templateModel: Model = objectMapper.readValue(template) + val templateModel: Model = PipelineUtils.fixedTemplateParam(objectMapper.readValue(template)) checkTemplateAtomsForExplicitVersion(templateModel, userId) val templateId = UUIDUtil.generate() dslContext.transaction { configuration -> @@ -382,7 +382,7 @@ class TemplateFacadeService @Autowired constructor( templateName = saveAsTemplateReq.templateName, versionName = INIT_TEMPLATE_NAME, userId = userId, - template = template, + template = JsonUtil.toJson(templateModel, formatted = false), storeFlag = false, version = client.get(ServiceAllocIdResource::class).generateSegmentId(TEMPLATE_BIZ_TAG_NAME).data, desc = null @@ -2382,6 +2382,9 @@ class TemplateFacadeService @Autowired constructor( stage.containers.forEach { container -> if (container is TriggerContainer) { container.params = PipelineUtils.cleanOptions(params = container.params) + container.templateParams = container.templateParams?.let { + PipelineUtils.cleanOptions(params = it) + } } if (container.containerId.isNullOrBlank()) { container.containerId = container.id diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt index 9aca356668b..1c6a622f6b3 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt @@ -79,7 +79,13 @@ class WebhookRequestService( externalId = matcher.getExternalId(), eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), - eventMessage = matcher.getMessage() ?: "", + eventMessage = matcher.getMessage()?.let { + if (it.length >= 128) { + it.substring(0, 128) + } else { + it + } + } ?: "", repositoryType = scmType.name, requestHeader = request.headers, requestParam = request.queryParams, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/yaml/PipelineYamlFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/yaml/PipelineYamlFacadeService.kt index baef71cd0c5..aea246c6a9c 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/yaml/PipelineYamlFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/yaml/PipelineYamlFacadeService.kt @@ -452,28 +452,14 @@ class PipelineYamlFacadeService @Autowired constructor( /** * 构建yaml流水线触发变量 */ - fun buildYamlManualParamMap(userId: String, projectId: String, pipelineId: String): Map? { + fun buildYamlManualParamMap(projectId: String, pipelineId: String): Map? { val pipelineYamlInfo = pipelineYamlInfoDao.get( dslContext = dslContext, projectId = projectId, pipelineId = pipelineId ) ?: return null - val repoHashId = pipelineYamlInfo.repoHashId - val repository = client.get(ServiceRepositoryResource::class).get( - projectId = projectId, - repositoryId = repoHashId, - repositoryType = RepositoryType.ID - ).data ?: return null - val setting = PacRepoSetting(repository = repository) - val event = PipelineYamlManualEvent( - userId = userId, - projectId = projectId, - repoHashId = repoHashId, - scmType = repository.getScmType() - ) - val action = eventActionFactory.loadManualEvent(setting = setting, event = event) return mutableMapOf( - BK_REPO_WEBHOOK_HASH_ID to BuildParameters(BK_REPO_WEBHOOK_HASH_ID, repoHashId), + BK_REPO_WEBHOOK_HASH_ID to BuildParameters(BK_REPO_WEBHOOK_HASH_ID, pipelineYamlInfo.repoHashId), PIPELINE_WEBHOOK_BRANCH to BuildParameters( - PIPELINE_WEBHOOK_BRANCH, action.data.context.defaultBranch ?: "" + PIPELINE_WEBHOOK_BRANCH, pipelineYamlInfo.defaultBranch ?: "" ) ) } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryConfigResourceImpl.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryConfigResourceImpl.kt index a989105bb62..228d1f966bb 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryConfigResourceImpl.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryConfigResourceImpl.kt @@ -50,6 +50,7 @@ class UserRepositoryConfigResourceImpl @Autowired constructor( } override fun list(): Result> { + // TODO 源码管理需要优化 val managers = ScmType.values().map { val status = when { it == ScmType.GITHUB && gitConfig.githubClientId.isBlank() -> diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryPacResourceImpl.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryPacResourceImpl.kt index 7b85f8e0dde..938cf3deaa4 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryPacResourceImpl.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryPacResourceImpl.kt @@ -35,11 +35,13 @@ import com.tencent.devops.common.web.RestResource import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.repository.api.UserRepositoryPacResource import com.tencent.devops.repository.service.RepositoryPacService +import com.tencent.devops.scm.config.GitConfig import org.springframework.beans.factory.annotation.Autowired @RestResource class UserRepositoryPacResourceImpl @Autowired constructor( - private val repositoryPacService: RepositoryPacService + private val repositoryPacService: RepositoryPacService, + private val gitConfig: GitConfig ) : UserRepositoryPacResource { override fun getPacProjectId( @@ -122,14 +124,19 @@ class UserRepositoryPacResourceImpl @Autowired constructor( } override fun supportScmType(): Result> { - return Result(listOf(ScmType.CODE_GIT).map { - IdValue( - id = it.name, - value = I18nUtil.getCodeLanMessage( - messageCode = "TRIGGER_TYPE_${it.name}", - defaultMessage = it.name + // TODO 源码管理需要优化 + return if (gitConfig.clientId.isBlank()) { + return Result(emptyList()) + } else { + Result(listOf(ScmType.CODE_GIT).map { + IdValue( + id = it.name, + value = I18nUtil.getCodeLanMessage( + messageCode = "TRIGGER_TYPE_${it.name}", + defaultMessage = it.name + ) ) - ) - }) + }) + } } } diff --git a/support-files/i18n/message_en_US.properties b/support-files/i18n/message_en_US.properties index 24a0b2f5b44..364ae164953 100644 --- a/support-files/i18n/message_en_US.properties +++ b/support-files/i18n/message_en_US.properties @@ -131,7 +131,7 @@ 2100131=The SSH private key format is not supported. Only RSA format private keys are supported. 2100132=The operation of third-party service [{0}] has failed. Failure details: {1} -2100133=Plugin[{0}]Merge Request Accept event type has been adjusted to action:merged for Merge Request event. Please switch version to 2.latest or above. +2100133=Trigger [{0}] Merge Request Accept event type has been adjusted to action:merged for Merge Request event. Please switch version to 2.latest or above. 2100135=SVN token is incorrect or SVN path does not have permission 2100136=SVN token is empty, please check the credential type. 2189500=daemon interrupted diff --git a/support-files/i18n/message_zh_CN.properties b/support-files/i18n/message_zh_CN.properties index 9b70b9b4270..4748ae998c7 100644 --- a/support-files/i18n/message_zh_CN.properties +++ b/support-files/i18n/message_zh_CN.properties @@ -131,7 +131,7 @@ 2100131=不支持的SSH私钥格式,仅支持RSA格式私钥 2100132=第三方服务[{0}]操作失败,失败详情:{1} -2100133=插件[{0}]Merge Request Accept事件类型已调整为Merge Request事件对应的监听动作:合并MR,请切换版本至2.latest及以上 +2100133=触发器[{0}]Merge Request Accept事件类型已调整为Merge Request事件对应的监听动作:合并MR,请切换版本至2.latest及以上 2100135=SVN token 不正确 或者 SVN 路径没有权限 2100136=SVN Token 为空, 请检查代码库的凭证类型 2189500=守护进程中断 diff --git a/support-files/sql/5001_init_dml/5001_ci_process-init_ddl_mysql.sql b/support-files/sql/5001_init_dml/5001_ci_process-init_ddl_mysql.sql index e5e699547de..cbb7edd1af7 100755 --- a/support-files/sql/5001_init_dml/5001_ci_process-init_ddl_mysql.sql +++ b/support-files/sql/5001_init_dml/5001_ci_process-init_ddl_mysql.sql @@ -2,8 +2,8 @@ SET NAMES utf8mb4; USE devops_ci_process; -- 空白流水线模板 -INSERT IGNORE INTO `T_TEMPLATE` (`VERSION`, `ID`, `TEMPLATE_NAME`, `PROJECT_ID`, `VERSION_NAME`, `CREATOR`, `CREATED_TIME`, `TEMPLATE`, `TYPE`, `CATEGORY`, `LOGO_URL`, `SRC_TEMPLATE_ID`, `STORE_FLAG`, `WEIGHT`) VALUES - (1, '072d516d300b4812a4f652f585eacc36', 'Blank', '', 'init', '', '2019-05-23 16:24:02', '{\n \"name\" : \"Blank\",\n \"desc\" : \"\",\n \"stages\" : [ {\n \"containers\" : [ {\n \"@type\" : \"trigger\",\n \"name\" : \"Trigger\",\n \"elements\" : [ {\n \"@type\" : \"manualTrigger\",\n \"name\" : \"Manual\",\n \"id\" : \"T-1-1-1\",\n \"properties\" : [ ]\n } ]\n } ],\n \"id\" : \"stage-1\"\n }]\n}', 'PUBLIC', '', NULL, NULL, 0, 100); +REPLACE INTO `T_TEMPLATE` (`VERSION`, `ID`, `TEMPLATE_NAME`, `PROJECT_ID`, `VERSION_NAME`, `CREATOR`, `CREATED_TIME`, `TEMPLATE`, `TYPE`, `CATEGORY`, `LOGO_URL`, `SRC_TEMPLATE_ID`, `STORE_FLAG`, `WEIGHT`, `DESC`) VALUES + (1, '072d516d300b4812a4f652f585eacc36', 'Default', '', 'init', '', '2019-05-23 16:24:02', '{\n \"name\" : \"Blank\",\n \"desc\" : \"\",\n \"stages\" : [ {\n \"containers\" : [ {\n \"@type\" : \"trigger\",\n \"name\" : \"Trigger\",\n \"elements\" : [ {\n \"@type\" : \"manualTrigger\",\n \"name\" : \"Manual\",\n \"id\" : \"T-1-1-1\",\n \"properties\" : [ ]\n } ]\n } ],\n \"id\" : \"stage-1\"\n }]\n}', 'PUBLIC', '', NULL, NULL, 0, 100, 'This is an empty pipeline.'); -- Stage预置标签 INSERT IGNORE INTO `T_PIPELINE_STAGE_TAG` (`ID`, `STAGE_TAG_NAME`, `WEIGHT`, `CREATOR`, `MODIFIER`, `CREATE_TIME`, `UPDATE_TIME`) VALUES @@ -29,4 +29,4 @@ INSERT IGNORE INTO `T_PIPELINE_RULE`(`ID`, `RULE_NAME`, `BUS_CODE`, `PROCESSOR`) INSERT IGNORE INTO `T_PIPELINE_RULE`(`ID`, `RULE_NAME`, `BUS_CODE`, `PROCESSOR`) VALUES ('5d6a9ab5f012418ab4827fcb98f564ad', 'BK_CI_PIPELINE_NAME', 'BUILD_NUM', 'BkVarProcessor'); -- 更新模板表UPDATE_TIME为空的历史记录 -UPDATE T_TEMPLATE SET UPDATE_TIME=CREATED_TIME WHERE UPDATE_TIME IS NULL; \ No newline at end of file +UPDATE T_TEMPLATE SET UPDATE_TIME=CREATED_TIME WHERE UPDATE_TIME IS NULL; diff --git a/support-files/templates/#etc#ci#application-repository.yml b/support-files/templates/#etc#ci#application-repository.yml index b6f27c3cc02..59e529d5b0b 100644 --- a/support-files/templates/#etc#ci#application-repository.yml +++ b/support-files/templates/#etc#ci#application-repository.yml @@ -25,8 +25,8 @@ scm: git: url: __BK_CI_REPOSITORY_GIT_URL__ apiUrl: __BK_CI_REPOSITORY_GIT_URL__/api/v3 - clientId: clientId - clientSecret: Secret + clientId: __BK_CI_REPOSITORY_GIT_CLIENT_ID__ + clientSecret: __BK_CI_REPOSITORY_GIT_CLIENT_SECRET__ redirectUrl: __BK_CI_PUBLIC_URL__/console/codelib redirectAtomMarketUrl: __BK_CI_PUBLIC_URL__/console/store/atomList gitHookUrl: __BK_CI_PUBLIC_URL__/ms/process/api/external/scm/codegit/commit