3.2.2. OpenShift Pipeline 概念

本指南提供了对管道(pipeline)概念的详细论述。

3.2.2.1. 任务(Task)

Task(任务)是 Pipeline 的构建块,它由按顺序执行的步骤组成。它基本上是一个输入和输出的功能。一个任务可以单独运行,也可以作为管道的一部分运行。任务(Task)可以重复使用,并可用于多个 Pipelines。

Step(步骤)是由任务顺序执行并实现特定目标(如构建镜像)的一系列命令。每个任务都作为 pod 运行,每个步骤都作为该 pod 中的容器运行。由于步骤在同一个 pod 中运行,所以它们可以访问同一卷来缓存文件、配置映射和 secret。

以下示例显示了 apply-manifests 任务。

apiVersion: tekton.dev/v1beta1 1
kind: Task 2
metadata:
  name: apply-manifests 3
spec: 4
  workspaces:
  - name: source
  params:
    - name: manifest_dir
      description: The directory in source that contains yaml manifests
      type: string
      default: "k8s"
  steps:
    - name: apply
      image: image-registry.openshift-image-registry.svc:5000/openshift/cli:latest
      workingDir: /workspace/source
      command: ["/bin/bash", "-c"]
      args:
        - |-
          echo Applying manifests in $(params.manifest_dir) directory
          oc apply -f $(params.manifest_dir)
          echo -----------------------------------
1
Task API 版本 v1beta1
2
Kubernetes 对象的类型,任务
3
此任务的唯一名称。
4
列出任务中的参数和步骤,以及任务使用的工作区(workspace)。

此任务启动 pod,并在该 pod 中使用指定镜像运行一个容器,以运行指定的命令。