云原生CI/CDDevOps后端【免费下载链接】pipelineA cloud-native Pipeline resource.项目地址https://gitcode.com/gh_mirrors/pipelin/pipeline点击查看免费下载导读本文以 Tekton Pipeline 的 API 参考文档为核心系统梳理云原生流水线中Pipeline、Task、PipelineRun、TaskRun、Run/CustomRun、ResolutionRequest、StepAction与VerificationPolicy等核心资源的类型定义、字段语义与版本演进。你将掌握tekton.dev与resolution.tekton.dev两个 API 组共 6 个包的资源结构、参数/结果/工作区/超时等关键字段的默认值与校验规则并能基于仓库中的源码与 CRD 文件准确编写与阅读 Pipeline 清单。一、API 包总览六个版本化包的职责划分Tekton Pipeline 的 API 被划分为两个 API 组Group并在各自组内按稳定性提供多个版本。文档中给出的完整包清单如下包PackageAPI 组主要资源resolution.tekton.dev/v1alpha1resolutionResolutionRequestresolution.tekton.dev/v1beta1resolutionResolutionRequesttekton.dev/unversionedtektonVolumesPod 卷的非版本化配置tekton.dev/v1tektonPipeline、PipelineRun、Task、TaskRuntekton.dev/v1alpha1tektonPipelineResource废弃、Run、StepAction、VerificationPolicytekton.dev/v1beta1tektonCustomRun、Pipeline、PipelineRun、StepAction、Task、TaskRun从源码结构看该仓库在 pkg/apis/pipeline/v1、pkg/apis/pipeline/v1beta1、pkg/apis/pipeline/v1alpha1、pkg/apis/resolution/v1beta1 与 pkg/apis/resolution/v1alpha1 目录中分别维护各版本的 Go 类型定义并通过 pkg/apis/pipeline/register.go 与 pkg/apis/resolution/register.go 完成 Scheme 注册。CRD 清单位于 config/300-crds 目录如 300-pipeline.yaml、300-task.yaml、300-resolutionrequest.yaml。关键版本策略tekton.dev/v1是稳定版本仓库中的Pipeline、Task、PipelineRun、TaskRun定义标注了kubebuilder:storageversion即作为存储版本使用tekton.dev/v1beta1中的同名资源已标记 Deprecated如Deprecated: Please use v1.Pipeline instead.保留仅为兼容旧客户端tekton.dev/v1alpha1中的PipelineResource已废弃Deprecated: Unused, preserved only for backwards compatibilityRun已被 v1beta1 的CustomRun取代resolution.tekton.dev/v1beta1是 ResolutionRequest 的存储版本见 pkg/apis/resolution/v1beta1/resolution_request_types.go 中kubebuilder:storageversion标注。二、ResolutionRequest远程资源解析请求的类型定义ResolutionRequest是一个用于“请求某个 Tekton 资源如 pipeline.yaml内容”的对象其文档定义同时存在于resolution.tekton.dev/v1alpha1与resolution.tekton.dev/v1beta1两个版本中。2.1 顶层对象apiVersion: resolution.tekton.dev/v1beta1 # 或 v1alpha1 kind: ResolutionRequest metadata: # 复用 Kubernetes ObjectMeta name: my-resolution namespace: my-namespace spec: # ResolutionRequestSpec可选 params: [] url: # 仅 v1beta1 提供alpha 稳定性级别 status: # ResolutionRequestStatus可选 data: refSource: {}字段说明字段类型说明apiVersionstringresolution.tekton.dev/v1alpha1或resolution.tekton.dev/v1beta1kindstring固定为ResolutionRequestmetadataObjectMeta遵循 Kubernetes API 规范specResolutionRequestSpec请求部分的信息statusResolutionRequestStatus请求状态最终包含被解析资源的内容2.2 ResolutionRequestSpec两版本的关键差异v1alpha1仅一个字段params类型为object (keys:string, values:string)即“运行时属性”传给 resolver 以确定如何解析被请求的资源例如仓库 URL、commit SHA、文件路径、认证类型等。v1beta1params的类型升级为[Param](#param)数组复用 tekton 的Param结构见 pkg/apis/pipeline/v1/param_types.go并新增url字段——运行时传给 resolver 的 URL。文档明确标注该字段目前处于ALPHA 稳定性级别受 alpha API 兼容性策略约束对应仓库 api_compatibility_policy.md。源码佐证在 pkg/apis/resolution/v1beta1/resolution_request_types.go 中ResolutionRequestSpec.Params的类型正是[]pipelinev1.Param并新增了URL string字段。2.3 ResolutionRequestStatus 与 StatusFieldsResolutionRequestStatus内嵌了ResolutionRequestStatusFields其字段包括字段类型说明observedGenerationinteger控制器最后处理的资源 GenerationconditionsConditions资源当前状态的最新可观测信息annotationsobject由 reconciler 向外传达的附加状态信息datastring被请求资源的解析内容内联在该对象的字符串表示中sourceRefSourcev1beta1 已废弃改用 RefSourcerefSourceRefSource远程数据的来源引用记录 url、digest 与 entrypoint其中RefSource的字段为uri构建定义来源的标识如https://github.com/tektoncd/catalogdigestURI 指定内容的密码学摘要集合如{sha1: f99d13e554ffcb696dee719fa85b695cb5b0f428}entryPoint构建的入口点通常是构建定义文件的路径或文件内目标标签如task/git-clone/0.10/git-clone.yaml。实用提示ResolutionRequest 与resolver机制配合使用。在PipelineRef/TaskRef中可以通过ResolverRef指定resolver: git等名称并传参从而从 Git 仓库、OCI Bundle、Hub 等远程位置拉取 Pipeline 或 Task 定义。详见仓库文档 resolution.md、git-resolver.md 与 tekton-bundle-contracts.md。三、tekton.dev/v1稳定版核心资源3.1 Pipeline 与 PipelineSpecPipeline描述要执行的一组 Tasks以及上游 Task 输出如何作为下游 Task 输入。顶层字段为apiVersion: tekton.dev/v1、kind: Pipeline、metadata、spec。PipelineSpec见 pkg/apis/pipeline/v1/pipeline_types.go字段字段类型说明displayNamestring面向 UI 的展示名可选descriptionstring面向 UI 的描述可选tasksPipelineTask 数组声明 Pipeline 运行时的 Task 图paramsParamSpecs运行 Pipeline 时必须提供的输入参数声明workspacesPipelineWorkspaceDeclaration 数组期望由 PipelineRun 提供的一组命名工作区resultsPipelineResult 数组Pipeline 运行后可输出的值finallyPipelineTask 数组在所有 tasks 成功结束、或 Pipeline 因失败即将结束前执行的任务列表PipelineResult由name、type取值string/array/object默认string其中 array 与 object 为 alpha 特性、description与value从底层步骤取值表达式组成。PipelineTask是 Pipeline 的执行单元关键字段包括name任务在 Pipeline 上下文中的名称与from、runAfter一起决定执行顺序taskRef/taskSpec引用已有 Task 或内联定义 TasktaskSpec可通过disable-inline-spec特性开关禁用whenWhenExpressions 守卫表达式全部求值为 true 才执行retriesTask 失败ConditionSucceeded 为 False时的重试次数runAfter强制执行顺序的任务名列表params/matrix传入参数与基于数组参数扇出任务的 Matrix 声明workspacesPipeline 工作区到 Task 工作区的映射timeoutTaskRun 超时默认 1 小时格式遵循 Go 的ParseDuration如1h30mpipelineRef/pipelineSpecalpha 字段需将enable-api-fields特性开关设为alpha用于将嵌套 Pipeline 作为子 PipelineRun 执行onErrorcontinuePipelineTask 失败后继续执行 DAG 其余部分或stopAndFail失败即停止并失败整个 PipelineRun。3.2 PipelineRun 与 PipelineRunSpecPipelineRun代表一次 Pipeline 执行它向 Pipeline 提供参数等输入并捕获 Task 执行的操作属性如 service account、tolerations。创建 PipelineRun 会为引用的 Pipeline 中的 Tasks 创建 TaskRuns。PipelineRunSpec字段字段类型说明pipelineRefPipelineRef引用具体 Pipeline 实例pipelineSpecPipelineSpec内联 Pipeline 定义可由disable-inline-spec禁用paramsParams参数名与值列表statusPipelineRunSpecStatus用于取消 pipelinerun 等timeoutsTimeoutFieldsPipeline 级超时见下文taskRunTemplatePipelineTaskRunTemplate应用于所有 Task 的运行模板podTemplate、serviceAccountNameworkspacesWorkspaceBinding 数组与 Pipeline 声明匹配的工作区绑定taskRunSpecsPipelineTaskRunSpec 数组针对具体 Task 的运行时配置managedBystring指明负责调和此资源的控制器未设置或为tekton.dev/pipeline时由默认 Tekton 控制器管理不可变字段TimeoutFields 粒度超时注意约束Timeouts.pipeline Timeouts.tasks Timeouts.finally字段说明pipeline整个 Pipeline 执行的最大允许时长tasks 与 finally 各自超时之和不得超过该值tasksPipeline 的 tasks 阶段最大允许时长finallyPipeline 的 finally 阶段最大允许时长PipelineRunStatus包含observedGeneration、conditions、annotations、startTime、completionTime、resultsPipelineRunResult 数组、pipelineSpec实例化运行时使用的确切 spec、skippedTasks、childReferences子 TaskRun/Run 的名称、PipelineTask 名与 API 版本/类型、finallyStartTime所有非 finally 任务完成、仅执行 finally 任务的时间点、provenance软件工件构建方式的关键认证元数据供 Tekton Chains 采集与spanContext链路追踪 span 上下文。其中ChildStatusReference用于指向 PipelineRun 内各 TaskRun 与 Run 的状态字段为name、displayName、pipelineTaskName与whenExpressionsSkippedTask记录因 when 表达式求值为 false 而跳过的任务及其SkippingReason。SkippingReason 完整取值表用于诊断任务为何被跳过Reason 展示文本含义When Expressions evaluated to falsewhen 表达式至少一个求值为 falseParent Tasks were skipped父任务被跳过PipelineRun was stoppingPipelineRun 正在停止PipelineRun was gracefully cancelledPipelineRun 被优雅取消PipelineRun was gracefully stoppedPipelineRun 被优雅停止Results were missing缺少必要的结果PipelineRun timeout has been reached超过整体超时PipelineRun Tasks timeout has been reached超过 Timeouts.TasksPipelineRun Finally timeout has been reached超过 Timeouts.FinallyMatrix Parameters have an empty arrayMatrix 参数包含空数组None任务未被跳过3.3 Task、TaskSpec 与 StepTask表示按顺序执行的一组步骤steps运行时由提供输入参数与资源的 TaskRun 触发。TaskSpec字段字段类型说明paramsParamSpecs运行 Task 所需的输入参数除非声明了默认值否则必须在 TaskRun 中提供displayName/descriptionstringUI 展示信息stepsStep 数组构建步骤顺序执行源码挂载于/workspacevolumesVolumes可供步骤挂载的卷集合对应 Pod.spec.volumesstepTemplateStepTemplate作为所有 step 容器基础的模板sidecarsSidecar 数组与 step 容器并行运行在 steps 之前开始、完成后结束workspacesWorkspaceDeclaration 数组该 Task 需要的卷resultsTaskResult 数组该 Task 可输出的值Step 字段v1 稳定版name、displayName、image、commandentrypoint 数组不经过 shell 执行、args、workingDir、envFrom、env、computeResources、volumeMounts、volumeDevices、imagePullPolicyAlways/Never/IfNotPresent:latest默认 Always否则 IfNotPresent、securityContext、script可执行文件内容非空时不能同时有 commandargs 会传给脚本、timeoutStep 超时默认永不超时、workspacesalpha 字段声明独占访问的 Task 工作区、onErrorcontinue/stopAndFail、stdoutConfig/stderrConfigStepOutputConfig可将 stdout/stderr 复制到容器本地文件系统的path、ref引用已有 StepAction、params、resultsStepResult 数组内联 Step 时可写入$(step.results.resultName.path)引用 StepAction 时不能使用改用 StepAction 声明的结果、whenStepWhenExpressions。Sidecar 与 Step 的差异Sidecar 拥有与 Step 几乎相同的数据结构但没有超时能力另含ports、livenessProbe、readinessProbe、startupProbe、lifecycle、stdin、stdinOnce、tty等容器级字段。ParamSpec / ParamType / ParamValue参数支持三种类型string默认、array、objectParamSpec支持default未提供输入值时的默认值与enum允许值的枚举设置后执行输入校验未设置则不校验properties用于支撑 key-value 对象的 JSON Schema 属性定义。ParamValue在 JSON 反序列化时可同时接受单个字符串或字符串数组。3.4 TaskRun 与 TaskRunSpecTaskRun代表单次 Task 执行是 Task 中步骤实际运行的方式。TaskRunSpec字段debugTaskRunDebug 断点配置breakpoints.onFailure可在步骤失败时暂停、beforeSteps指定暂停前的步骤列表、params、serviceAccountName、taskRef/taskSpec二者至多指定一个、status取消 TaskRun、statusMessage、retries失败重试次数、timeout单次重试尝试超时默认 1 小时、podTemplate、workspaces、stepSpecs/sidecarSpecsalpha 特性按名称覆盖步骤/边车的 computeResources、computeResources、managedBy不可变。TaskRunStatus的字段包括podName执行步骤的 Pod 名、startTime、completionTime、stepsStepState 数组报告各 step 容器的 waiting/running/terminated 状态与 results、provenance、inputs/outputs 工件、retriesStatus重试历史用于留存失败记录、resultsTaskRunResult 数组、artifacts输入输出工件集合inputs/outputs各为 Artifact 数组Artifact 含name、valuesdigest 与 uri与buildOutput标记、sidecars、taskSpec实例化时反引用后的确切 spec、provenance、spanContext。3.5 工作区Workspace体系WorkspaceDeclarationTask 声明name、description、mountPath覆盖挂载目录、readOnly默认 false 可写、optional默认 false 即必需PipelineWorkspaceDeclarationPipeline 声明name、description、optionalWorkspaceBinding运行期绑定name、subPath、volumeClaimTemplate控制器为每个 PipelineRun 创建唯一 PVC、persistentVolumeClaim、emptyDir、configMap、secret、projected、csi后两者二选一约束适用于 PVC 与 emptyDirWorkspacePipelineTaskBindingPipeline 到 Task 的映射nameTask 声明名、workspacePipeline 声明名、subPathWorkspaceUsageStep/Sidecar 独占访问name、mountPath覆盖 Task 声明中的 mountPath。四、tekton.dev/v1beta1过渡版本与 CustomRuntekton.dev/v1beta1包中的Pipeline、PipelineRun、Task、TaskRun均标注Deprecated: Please use v1.* instead.字段与 v1 基本一致但保留了以下 v1 中已移除或改名的历史字段PipelineRef.bundle/TaskRef.bundleTekton Bundle URL 引用已废弃改用ResolverRef bundles resolver字段保留仅为 Go 客户端向后兼容不再使用PipelineRunSpec.resources/timeoutresources为废弃的 PipelineResource 绑定timeout已废弃改用timeouts.pipelinePipelineRunStatus.taskRuns/runsmap 形式自 v0.45.0 起不再填充改用childReferencesTaskRunSpec.stepOverrides/sidecarOverrides对应 v1 的stepSpecs/sidecarSpecsTaskSpec.resourcesTaskResources废弃的 PipelineResource 声明Provenance.configSource废弃改用refSource。CustomRun 是 v1beta1 包新增的核心资源用于执行自定义 TaskCustom TaskCustomRunSpec字段customRefTaskRef、customSpecEmbeddedCustomRunSpec 内嵌自定义任务定义、params、status取消、statusMessage、retries向自定义任务传播重试计数、serviceAccountName、timeout自定义任务超时、workspaces。CustomRunStatus状态消息常量包括CustomRun cancelled as the PipelineRun it belongs to has been cancelled.与CustomRun cancelled as the PipelineRun it belongs to has timed out.。历史对应v1alpha1 中的Run表示单次自定义任务执行其RunSpec字段ref、spec、params、status、statusMessage、retries、serviceAccountName、podTemplate、timeout、workspaces与 CustomRun 高度相似CustomRun 是其演进版本。迁移指南见 migrating-v1alpha1.Run-to-v1beta1.CustomRun.md。五、tekton.dev/v1alpha1遗留资源与安全/复用能力该包包含 4 种资源类型5.1 PipelineResource废弃PipelineResource描述 Task 的输入或输出资源文档明确标注Deprecated: Unused, preserved only for backwards compatibility无控制器为其工作。PipelineResourceSpec字段为description、type、paramsResourceParam、secretsSecretParam。5.2 Run废弃被 CustomRun 取代如前所述Run用于执行自定义任务RunSpecStatus仅定义RunCancelled一个取值。5.3 StepAction步骤复用单元StepAction表示 Step 的可执行组件Step 只能从集群内或通过远程解析引用它。StepActionSpec字段description、image、command、args、env、script非空时不能有 commandargs 传给脚本、workingDir、paramsParamSpecs除非声明默认值否则需在 Steps 中提供、resultsStepResult 数组、securityContextStepAction 中的设置优先于 Task 中的值、volumeMounts。在Step.refRef 结构中可以引用 StepActionRef字段为name与ResolverRef支持从 Git 等远程位置引用。StepAction的 v1beta1 版本存在于tekton.dev/v1beta1包中。实践示例见 examples/v1/taskruns/stepaction.yaml 与 examples/v1/taskruns/stepaction-params.yaml。5.4 VerificationPolicy资源签名验证策略VerificationPolicy定义验证 Tekton 资源的规则可将“资源来源”映射到“公钥列表”在验证资源时使用对应的公钥。VerificationPolicySpec字段字段类型说明resourcesResourcePattern 数组受该策略约束的资源来源模式正则匹配。例如 git resolver 场景https://github.com/tektoncd/catalog.gitauthoritiesAuthority 数组签名验证规则modeModeTypeenforce默认验证失败则使 taskrun/pipelinerun 失败或warn仅记录告警不失败ResourcePattern.pattern的文档示例GitHub 资源https://github.com/tektoncd/catalog.git、https://github.com/tektoncd/*Bundle 资源gcr.io/tekton-releases/catalog/upstream/git-clone、gcr.io/tekton-releases/catalog/upstream/*Hub 资源https://artifacthub.io/*。Authority包含name与keyKeyRefKeyRef支持secretRef引用存有密钥的 Secret、data内联公钥、kmsKMS URL目前尚未支持与hashAlgorithm默认sha256可选sha224/sha256/sha384/sha512。深入阅读该机制与 pkg/trustedresources 包含 verifier 与 verify 逻辑及 docs/trusted-resources.md 配合使用CRD 定义见 config/300-crds/300-verificationpolicy.yaml密钥测试数据位于 test/trustedresources-keys。六、tekton.dev/unversioned非版本化的 Volumes该包仅包含Volumes类型其底层类型为 Kubernetes 的VolumeAPI v1被EmbeddedTask与TaskSpec引用。它完整继承了 Kubernetes 的卷类型体系包括hostPath、emptyDir、secret、configMap、persistentVolumeClaim、nfs、projected、csi、ephemeral、image等。值得关注的是较新的卷类型语义ephemeral生命周期与 Pod 绑定适用于仅 Pod 运行期间需要的卷、需要快照恢复/容量跟踪、由 storage class 指定驱动并支持动态供应的场景Pod 同时可以使用临时卷与持久卷image将 OCI 对象容器镜像或工件拉取并挂载到 kubelet 主机按Always/Never/IfNotPresent拉取策略解析只读ro且不可执行noexec挂载1.33 之前不支持 subPath 挂载。七、跨版本通用类型速查以下类型在多个版本包中重复出现字段语义保持一致Param / ParamSpec / ParamValue / Params / ParamType / ParamSpecs参数体系类型为string/array/objectResultsType区分string、array、object结果类型注意与用于判定 RunResult 是否来自 task result 的 ResultType 不同WhenExpression / WhenExpressions字段input、operator、values非空数组、celCEL 表达式可选所有表达式需为 true 才执行守卫任务Provenance / RefSource / ConfigSource远程构建定义的来源元数据v1beta1 中ConfigSource已废弃统一为RefSourceuri、digest、entryPointProvenance.featureFlags记录运行期使用的特性开关TimeoutFieldsPipeline 级pipeline/tasks/finally三档超时OnErrorTypeStep 级stopAndFail/continuePipelineTaskOnErrorTypePipelineTask 级stopAndFail/continueArtifact / ArtifactValue / Artifacts工件输入输出记录含digest按 Algorithm 映射与uriRetriesStatus重试历史内联TaskRunStatusFields且不再重复记录时间。八、如何在仓库中印证与使用这些 API类型定义源头各版本的 Go 类型集中在 pkg/apis/pipeline/v1、pkg/apis/pipeline/v1beta1、pkg/apis/pipeline/v1alpha1例如Pipeline/PipelineSpec/PipelineTask见 pkg/apis/pipeline/v1/pipeline_types.goResolutionRequest见 pkg/apis/resolution/v1beta1/resolution_request_types.goCRD 声明config/300-crds 下的 300-*.yaml 是各资源在集群中的最终结构声明OpenAPI v3 schema可运行示例examples/v1/pipelineruns 与 examples/v1/taskruns 提供了大量实战清单覆盖 params、results、workspaces、when 表达式、matrix、stepaction、sidecar、超时覆盖等全部文档字段的用法行为校验各类型对应的*_validation.go与*_test.go如 pkg/apis/pipeline/v1/pipeline_validation_test.go印证了文档中 Validation 列的约束如Timeouts.pipeline tasks finally、values非空、taskRef与taskSpec互斥等运行与查看通过kubectl apply提交上述 CR 清单用kubectl get/kubectl describe观察status中的 conditions、results、skippedTasks、childReferences 等字段。结语Tekton Pipeline 通过tekton.dev与resolution.tekton.dev两组 API、多个版本化的包把“流水线定义Pipeline/Task”“运行实例PipelineRun/TaskRun/Run/CustomRun”“远程解析ResolutionRequest/ResolverRef”“复用单元StepAction”与“安全信任VerificationPolicy”完整地纳入了 Kubernetes 声明式体系。理解每个包的职责、稳定级别与字段语义是编写可长期维护的 CI/CD 清单、排查运行状态以及评估版本迁移影响的前提。建议新资源一律使用tekton.dev/v1与resolution.tekton.dev/v1beta1遗留字段仅用于兼容旧客户端。赞分享云原生CI/CDDevOps后端【免费下载链接】pipelineA cloud-native Pipeline resource.项目地址https://gitcode.com/gh_mirrors/pipelin/pipeline点击查看免费下载相关推荐Tekton Pipeline 任务(Task)配置完全指南Tekton Pipeline 任务 Task 配置完全指南 概述 在Tekton Pipeline中Task 任务 是构建CI/CD流程的基本执行单元。本文云原生CI/CDDevOps后端Tekton Pipelines 核心实体模型Task、Pipeline 与其运行资源的完整解析Tekton Pipelines 核心实体模型Task、Pipeline 与其运行资源的完整解析 本文基于 Tekton Pipelines 项目的官方文档入云原生CI/CDDevOps后端Tekton Pipeline Git Resolver 完整指南从 Git 仓库远程解析 Task 与 Pipeline 资源Tekton Pipeline Git Resolver 完整指南从 Git 仓库远程解析 Task 与 Pipeline 资源 导读 Git Resolve云原生CI/CDDevOps后端创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
