3.2.2.3. Pipelines

Pipeline 一组 Task(任务)资源,它们按特定顺序执行。执行它们是为了构建复杂的工作流,以自动化应用程序的构建、部署和交付。您可以使用包含一个或多个任务的管道为应用程序定义 CI/CD 工作流。

Pipeline 资源的定义由多个字段或属性组成,它们一起可让管道实现一个特定目标。每个 Pipeline 资源定义必须至少包含一个Task(任务)资源,用于控制特定输入并生成特定的输出。Pipeline 定义也可以根据应用程序要求包括 ConditionsWorkspacesParametersResources

以下示例显示了 build-and-deploy pipeline,它使用 buildah ClusterTask 资源从 Git 存储库构建应用程序镜像:

apiVersion: tekton.dev/v1beta1 1
kind: Pipeline 2
metadata:
  name: build-and-deploy 3
spec: 4
  workspaces: 5
  - name: shared-workspace
  params: 6
  - name: deployment-name
    type: string
    description: name of the deployment to be patched
  - name: git-url
    type: string
    description: url of the git repo for the code of deployment
  - name: git-revision
    type: string
    description: revision to be used from repo of the code for deployment
    default: "pipelines-1.4"
  - name: IMAGE
    type: string
    description: image to be built from the code
  tasks: 7
  - name: fetch-repository
    taskRef:
      name: git-clone
      kind: ClusterTask
    workspaces:
    - name: output
      workspace: shared-workspace
    params:
    - name: url
      value: $(params.git-url)
    - name: subdirectory
      value: ""
    - name: deleteExisting
      value: "true"
    - name: revision
      value: $(params.git-revision)
  - name: build-image 8
    taskRef:
      name: buildah
      kind: ClusterTask
    params:
    - name: TLSVERIFY
      value: "false"
    - name: IMAGE
      value: $(params.IMAGE)
    workspaces:
    - name: source
      workspace: shared-workspace
    runAfter:
    - fetch-repository
  - name: apply-manifests 9
    taskRef:
      name: apply-manifests
    workspaces:
    - name: source
      workspace: shared-workspace
    runAfter: 10
    - build-image
  - name: update-deployment
    taskRef:
      name: update-deployment
    workspaces:
    - name: source
      workspace: shared-workspace
    params:
    - name: deployment
      value: $(params.deployment-name)
    - name: IMAGE
      value: $(params.IMAGE)
    runAfter:
    - apply-manifests
1
Pipeline API 版本 v1beta1
2
指定 Kubernetes 对象的类型。在本例中, Pipeline
3
此 Pipeline 的唯一名称。
4
指定 Pipeline 的定义和结构。
5
Pipeline 中所有任务使用的工作区。
6
Pipeline 中所有任务使用的参数。
7
指定 Pipeline 中使用的任务列表。
8
任务 build-image 使用 buildah ClusterTask 从给定的 Git 仓库构建应用程序镜像。
9
任务 apply-manifests 使用相同名称的用户定义的任务。
10
指定在 Pipeline 中运行任务的顺序。在本例中,apply-manifests 任务仅在 build-image 任务完成后运行。