Skip to content

Commit

Permalink
feat:【PAC模板】流水线模板支持PAC特性 TencentBlueKing#11414
Browse files Browse the repository at this point in the history
基本结构、类、方法设计
  • Loading branch information
fcfang123 committed Jan 22, 2025
1 parent 34f1e7e commit b616305
Show file tree
Hide file tree
Showing 38 changed files with 1,912 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import com.tencent.devops.process.yaml.transfer.pojo.ModelTransferInput
import com.tencent.devops.process.yaml.transfer.pojo.YamlTransferInput
import com.tencent.devops.process.yaml.v3.enums.SyntaxDialectType
import com.tencent.devops.process.yaml.v3.models.Concurrency
import com.tencent.devops.process.yaml.v3.models.Extends
import com.tencent.devops.process.yaml.v3.models.GitNotices
import com.tencent.devops.process.yaml.v3.models.IPreTemplateScriptBuildYamlParser
import com.tencent.devops.process.yaml.v3.models.Notices
Expand Down Expand Up @@ -203,7 +202,6 @@ class ModelTransfer @Autowired constructor(
}
)
}
checkExtends(yamlInput.yaml.templateFilter().extends, model)
yamlInput.aspectWrapper.setModel4Model(model, PipelineTransferAspectWrapper.AspectType.AFTER)
return model
}
Expand Down Expand Up @@ -236,14 +234,6 @@ class ModelTransfer @Autowired constructor(
)
}
}
if (modelInput.model.template != null) {
yaml.extends = Extends(
modelInput.model.template!!,
modelInput.model.ref,
modelInput.model.variables
)
return yaml
}

val triggerOn = makeTriggerOn(modelInput)
when (modelInput.version) {
Expand Down Expand Up @@ -464,12 +454,4 @@ class ModelTransfer @Autowired constructor(
}
return labels
}

private fun checkExtends(extends: Extends?, model: Model) {
if (extends != null) {
model.template = extends.template
model.ref = extends.ref
model.variables = extends.variables
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.common.pipeline

import com.tencent.devops.common.pipeline.pojo.BuildFormProperty
import io.swagger.v3.oas.annotations.media.Schema

@Schema(title = "流水线模版函数")
interface ITemplateFunction {
@get:Schema(title = "来源于模版", required = false)
var fromTemplate: Boolean?
@get:Schema(title = "模板ID", required = false)
var templateId: String?
@get:Schema(title = "版本", required = false)
var templateVersion: Int?
@get:Schema(title = "模板参数构建", required = false)
var templateParams: List<BuildFormProperty>?
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.tencent.devops.common.pipeline.event.PipelineCallbackEvent
import com.tencent.devops.common.pipeline.event.ProjectPipelineCallBack
import com.tencent.devops.common.pipeline.pojo.time.BuildRecordTimeCost
import com.tencent.devops.common.pipeline.pojo.transfer.Resources
import com.tencent.devops.common.pipeline.template.ITemplateModel
import io.swagger.v3.oas.annotations.media.Schema

@Suppress("ALL")
Expand Down Expand Up @@ -67,15 +68,12 @@ data class Model(
var staticViews: List<String> = emptyList(),
@get:Schema(title = "各项耗时", required = true)
var timeCost: BuildRecordTimeCost? = null,
@get:Schema(title = "模板地址", required = true)
override var template: String? = null,
@get:Schema(title = "模板版本", required = true)
override var ref: String? = null,
@get:Schema(title = "模板入参", required = true)
override var variables: Map<String, String>? = null,
@get:Schema(title = "模板资源", required = true)
val resources: Resources? = null
) : IModelTemplate {
) : ITemplateModel {
companion object {
const val classType = "model"
}
@get:Schema(title = "提交时流水线最新版本号", required = false)
var latestVersion: Int = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ package com.tencent.devops.common.pipeline.container
import com.fasterxml.jackson.annotation.JsonSubTypes
import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.tencent.devops.common.api.util.JsonUtil
import com.tencent.devops.common.pipeline.IModelTemplate
import com.tencent.devops.common.pipeline.ITemplateFunction
import com.tencent.devops.common.pipeline.pojo.element.Element
import com.tencent.devops.common.pipeline.pojo.time.BuildRecordTimeCost
import io.swagger.v3.oas.annotations.media.Schema
Expand All @@ -40,9 +40,10 @@ import io.swagger.v3.oas.annotations.media.Schema
@JsonSubTypes(
JsonSubTypes.Type(value = TriggerContainer::class, name = TriggerContainer.classType),
JsonSubTypes.Type(value = NormalContainer::class, name = NormalContainer.classType),
JsonSubTypes.Type(value = VMBuildContainer::class, name = VMBuildContainer.classType)
JsonSubTypes.Type(value = VMBuildContainer::class, name = VMBuildContainer.classType),
JsonSubTypes.Type(value = JobTemplateContainer::class, name = JobTemplateContainer.classType)
)
interface Container : IModelTemplate {
interface Container : ITemplateFunction {
var id: String? // seq id
var name: String
var elements: List<Element>
Expand Down Expand Up @@ -110,4 +111,6 @@ interface Container : IModelTemplate {
fun containerEnabled(): Boolean

fun setContainerEnable(enable: Boolean)

fun copyElements(elements: List<Element>): Container
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* 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.common.pipeline.container

import com.tencent.devops.common.pipeline.pojo.BuildFormProperty
import com.tencent.devops.common.pipeline.pojo.element.Element
import com.tencent.devops.common.pipeline.pojo.time.BuildRecordTimeCost
import io.swagger.v3.oas.annotations.media.Schema

@Schema(title = "流水线模型-模版容器")
data class JobTemplateContainer(
@get:Schema(title = "构建容器序号id", required = false, readOnly = true)
override var id: String? = null,
@get:Schema(title = "容器名称", required = true)
override var name: String = "",
@get:Schema(title = "任务集合", required = true)
override var elements: List<Element> = listOf(),
@get:Schema(title = "状态", required = true, readOnly = true)
override var status: String? = null,
@get:Schema(title = "系统运行时间", required = false)
@Deprecated("即将被timeCost代替")
override var startEpoch: Long? = null,
@get:Schema(title = "系统耗时(开机时间)", required = false, readOnly = true)
@Deprecated("即将被timeCost代替")
override var systemElapsed: Long? = null,
@get:Schema(title = "插件执行耗时", required = false, readOnly = true)
@Deprecated("即将被timeCost代替")
override var elementElapsed: Long? = null,
@get:Schema(title =
"是否可重试-仅限于构建详情展示重试,目前未作为编排的选项,暂设置为null不存储",
required = false,
readOnly = true
)
override var canRetry: Boolean? = null,
@get:Schema(title = "构建容器顺序ID(同id值)", required = false, readOnly = true)
override var containerId: String? = null,
@get:Schema(title = "容器唯一ID", required = false, readOnly = true)
override var containerHashId: String? = null,
@get:Schema(title = "构建环境启动状态", required = false, readOnly = true)
override var startVMStatus: String? = null,
@get:Schema(title = "容器运行次数", required = false, readOnly = true)
override var executeCount: Int? = null,
@get:Schema(title = "用户自定义ID", required = false, hidden = false)
override var jobId: String? = null,
@get:Schema(title = "是否包含post任务标识", required = false, readOnly = true)
override var containPostTaskFlag: Boolean? = null,
@get:Schema(title = "是否为构建矩阵", required = false, readOnly = true)
override var matrixGroupFlag: Boolean? = false,
@get:Schema(title = "各项耗时", required = true)
override var timeCost: BuildRecordTimeCost? = null,
@get:Schema(title = "开机任务序号", required = false, readOnly = true)
override var startVMTaskSeq: Int? = null,
@get:Schema(title = "来源于模版", required = false)
override var fromTemplate: Boolean? = false,
@get:Schema(title = "模板ID", required = false)
override var templateId: String? = null,
@get:Schema(title = "版本", required = false)
override var templateVersion: Int? = null,
@get:Schema(title = "模板参数构建", required = false)
override var templateParams: List<BuildFormProperty>? = null
) : Container {
companion object {
const val classType = "jobTemplate"
}

override fun getClassType() = classType

override fun getContainerById(vmSeqId: String): Container? {
return if (id == vmSeqId) this else null
}

override fun retryFreshMatrixOption() = Unit

override fun fetchGroupContainers(): List<Container>? = null

override fun fetchMatrixContext(): Map<String, String>? = null

override fun containerEnabled(): Boolean {
return true
}

override fun setContainerEnable(enable: Boolean) = Unit

override fun transformCompatibility() {
super.transformCompatibility()
}

override fun copyElements(elements: List<Element>): Container {
return this.copy(elements = elements)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ package com.tencent.devops.common.pipeline.container
import com.tencent.devops.common.pipeline.NameAndValue
import com.tencent.devops.common.pipeline.option.JobControlOption
import com.tencent.devops.common.pipeline.option.MatrixControlOption
import com.tencent.devops.common.pipeline.pojo.BuildFormProperty
import com.tencent.devops.common.pipeline.pojo.element.Element
import com.tencent.devops.common.pipeline.pojo.time.BuildRecordTimeCost
import io.swagger.v3.oas.annotations.media.Schema
Expand Down Expand Up @@ -102,9 +103,14 @@ data class NormalContainer(
var matrixContext: Map<String, String>? = null,
@get:Schema(title = "分裂后的容器集合(分裂后的父容器特有字段)", required = false)
var groupContainers: MutableList<NormalContainer>? = null,
override var template: String? = null,
override var ref: String? = null,
override var variables: Map<String, String>? = null
@get:Schema(title = "来源于模版", required = false)
override var fromTemplate: Boolean? = false,
@get:Schema(title = "模板ID", required = false)
override var templateId: String? = null,
@get:Schema(title = "版本", required = false)
override var templateVersion: Int? = null,
@get:Schema(title = "模板参数构建", required = false)
override var templateParams: List<BuildFormProperty>? = null
) : Container {
companion object {
const val classType = "normal"
Expand Down Expand Up @@ -151,4 +157,8 @@ data class NormalContainer(
}
super.transformCompatibility()
}

override fun copyElements(elements: List<Element>): Container {
return this.copy(elements = elements)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@

package com.tencent.devops.common.pipeline.container

import com.tencent.devops.common.pipeline.IModelTemplate
import com.tencent.devops.common.pipeline.ITemplateFunction
import com.tencent.devops.common.pipeline.option.StageControlOption
import com.tencent.devops.common.pipeline.pojo.BuildFormProperty
import com.tencent.devops.common.pipeline.pojo.StagePauseCheck
import com.tencent.devops.common.pipeline.pojo.time.BuildRecordTimeCost
import io.swagger.v3.oas.annotations.media.Schema
Expand Down Expand Up @@ -71,10 +72,15 @@ data class Stage(
var executeCount: Int? = null,
@get:Schema(title = "各项耗时", required = true)
var timeCost: BuildRecordTimeCost? = null,
override var template: String? = null,
override var ref: String? = null,
override var variables: Map<String, String>? = null
) : IModelTemplate {
@get:Schema(title = "来源于模版", required = false)
override var fromTemplate: Boolean? = false,
@get:Schema(title = "模板ID", required = false)
override var templateId: String? = null,
@get:Schema(title = "版本", required = false)
override var templateVersion: Int? = null,
@get:Schema(title = "模板参数构建", required = false)
override var templateParams: List<BuildFormProperty>? = null
) : ITemplateFunction {
/**
* 刷新stage的所有配置,如果是初始化则重置所有历史数据
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ data class TriggerContainer(
@get:Schema(title = "参数化构建", required = false)
var params: List<BuildFormProperty> = listOf(),
@get:Schema(title = "模板参数构建", required = false)
var templateParams: List<BuildFormProperty>? = null,
override var templateParams: List<BuildFormProperty>? = null,
@get:Schema(title = "构建版本号", required = false)
var buildNo: BuildNo? = null,
@get:Schema(title =
Expand All @@ -82,9 +82,12 @@ data class TriggerContainer(
override var timeCost: BuildRecordTimeCost? = null,
@get:Schema(title = "开机任务序号", required = false, readOnly = true)
override var startVMTaskSeq: Int? = null,
override var template: String? = null,
override var ref: String? = null,
override var variables: Map<String, String>? = null
@get:Schema(title = "来源于模版", required = false)
override var fromTemplate: Boolean? = false,
@get:Schema(title = "模板ID", required = false)
override var templateId: String? = null,
@get:Schema(title = "版本", required = false)
override var templateVersion: Int? = null
) : Container {
companion object {
const val classType = "trigger"
Expand All @@ -111,4 +114,8 @@ data class TriggerContainer(
override fun transformCompatibility() {
super.transformCompatibility()
}

override fun copyElements(elements: List<Element>): Container {
return this.copy(elements = elements)
}
}
Loading

0 comments on commit b616305

Please sign in to comment.