Tekton系列之实践篇-从触发到完成的完整执行过程
以下介绍的是基于 Gitee 仓库 的 Tekton 工作流程
操作流程
定义task
克隆代码的task
# task-clone.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: git-clone
spec:
workspaces:
- name: source # 工作目录
params:
- name: repo-url # 你的 Gitee 仓库地址
type: string
default: "https://gitee.com/wyxsxx/wyx123.git"
- name: branch # 分支名称
type: string
default: "main"
steps:
- name: clone
image: alpine/git # 使用轻量级 Git 镜像
script: |
git clone -b $(params.branch) $(params.repo-url) $(workspaces.source.path)/app
执行自定义脚本的 Task
# task-script.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: run-script
spec:
workspaces:
- name: source
steps:
- name: run-custom-script
image: alpine:3.15 # 按需替换为 Python/Node.js 等镜像
workingDir: "$(workspaces.source.path)/app"
script: |
# 这里执行你的自定义脚本(示例:打印文件列表)
echo "=== 文件列表 ==="
ls -l
echo "==============="
定义 Pipeline
# pipeline.yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: simple-demo-pipeline
spec:
worksp