快速开始
Target Audience
本指南适用于希望将 Git 仓库连接到现有 PAC 安装并触发第一个 PipelineRun 的用户。
目录
IntroductionEstimated Reading TimePrerequisitesStep 1: Configure RepositoryConfirm tkn pac PluginCreate GitLab Personal Access TokenConfigure Repository with tkn pacStep 2: Create Your First PipelineStep 3: Test the PipelineTrigger via PushTrigger via Merge RequestCheck Pipeline StatusNext StepsIntroduction
您将:
- 使用
tkn pac创建 PACRepository连接 - 向仓库中添加一个简单的
PipelineRun定义 - 触发并检查第一次运行
Estimated Reading Time
10-15 分钟
Prerequisites
- PAC 已部署,并已对 Git provider 网络暴露。请参见 Manage PAC Component。
- 您已获取 PAC webhook URL。请参见 Get the PAC Webhook URL。
- 您知道 PAC namespace。默认值为
tekton-pipelines。 - 已为目标集群配置
kubectl。 - 已安装带有
pac插件的tknCLI。请参见 tkn pac Command Reference。 - 您对 Git 仓库具有管理员或维护者访问权限。
Step 1: Configure Repository
以下步骤以 tkn pac CLI 和 GitLab 为例。对于 GitHub 或基于 manifest 的设置,请参见 Configure GitHub Repository 或 Configure GitLab Repository。
Namespace Parameters
--pac-namespace是 PAC 部署所在的 namespace。默认值为tekton-pipelines。- 用于 pipeline namespace 的交互式提示会在其中创建
Repository和PipelineRun资源。请在运行命令之前先创建该 namespace。
Confirm tkn pac Plugin
确认插件可用:
示例输出:
Create GitLab Personal Access Token
- 转到 GitLab → Settings → Access Tokens
- 创建一个具有
apiscope 的 token - 安全保存该 token
Configure Repository with tkn pac
从 Git 仓库目录中运行该命令。.tekton 目录将创建在当前工作目录中。
如果 PAC 部署在不同的 namespace 中,请替换 tekton-pipelines。
按照交互式提示操作:
- 输入 Git 仓库 URL(可自动从当前目录检测,或手动输入)
- 输入 pipelines 的 namespace,例如
project-pipelines。该 namespace 必须已存在。 - 此时将创建 Repository CR
- 输入 GitLab project ID(可在 project settings → General 中找到)
- 输入来自 Get the PAC Webhook URL 的 PAC webhook URL
- 输入 webhook secret(或按 Enter 使用自动生成的默认值)
- 输入 GitLab access token(您创建的 Personal Access Token)
- 输入 GitLab API URL(默认值:
https://gitlab.com,或输入您自托管的 GitLab URL)
该命令将:
- 在所选 namespace 中创建
Repository资源 - 自动配置 GitLab webhook
- 使用凭据创建 Kubernetes Secret
- 在您的仓库中生成
.tekton/pipelinerun.yaml模板
Step 2: Create Your First Pipeline
tkn pac create repo 命令会在 .tekton/pipelinerun.yaml 中创建一个基础模板。编辑它以定义您的 pipeline:
提交并推送到您的仓库:
注意:
- 将
<your-branch-name>替换为您的分支名称(例如,main、master或develop) - 确保注解
pipelinesascode.tekton.dev/on-target-branch与您的分支名称匹配。例如,如果您的分支是main,请使用"[refs/heads/main]";如果是test,请使用"[refs/heads/test]" - 如需匹配多个分支,请使用逗号分隔的值:
"[main, develop]"或"[refs/heads/main,refs/heads/develop]" - 如需匹配所有分支,请使用:
"[refs/heads/*]"
Step 3: Test the Pipeline
Trigger via Push
向 pipeline 注解中指定的分支推送一个 commit,以触发 pipeline:
Trigger via Merge Request
创建一个 Merge Request 以触发 pipeline:
然后在 GitLab 中创建一个 Merge Request。
Check Pipeline Status
查看该 namespace 中的 PipelineRuns:
示例输出:
查看 pipeline 日志:
示例输出:
示例输出:
Next Steps
- Manage PAC Component - 部署、更新和卸载指南
- Guides - 端到端仓库配置演练
- Define PipelineRuns in Git - PipelineRun 文件和触发注解
- Trigger PAC Pipelines - 自动事件和评论命令