Pipelines CLI (tkn)参考


Red Hat OpenShift Pipelines 1.18

OpenShift Pipelines 的 tkn CLI 参考

Red Hat OpenShift Documentation Team

摘要

本文档提供有关如何为 OpenShift Pipelines 安装、配置和使用 tkn CLI 工具的信息。

第 1 章 安装 tkn

使用 CLI 工具从终端管理 Red Hat OpenShift Pipelines。您可以在不同的平台中安装 CLI 工具。

注意

归档和 RPM 都包含以下可执行文件:

  • tkn
  • tkn-pac
  • opc
重要

使用 opc CLI 工具运行 Red Hat OpenShift Pipelines 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

1.1. 在 Linux 上安装 Red Hat OpenShift Pipelines CLI

对于 Linux 发行版,您可以将 CLI 下载为 tar.gz 存档。

  1. 解包存档:

    $ tar xvzf <file>
    Copy to clipboard
  2. 将您的 tkn, tkn-pac, 和 opc 文件添加到 PATH 环境变量中。
  3. 要查看您的 PATH,请运行以下命令:

    $ echo $PATH
    Copy to clipboard

1.2. 使用 RPM 在 Linux 上安装 Red Hat OpenShift Pipelines CLI

对于 Red Hat Enterprise Linux (RHEL) 版本 8,您可以使用 RPM 安装 Red Hat OpenShift Pipelines CLI。

先决条件

  • 您的红帽帐户必须具有有效的 OpenShift Container Platform 订阅。
  • 您在本地系统中有 root 或者 sudo 权限。

流程

  1. 使用 Red Hat Subscription Manager 注册:

    # subscription-manager register
    Copy to clipboard
  2. 获取最新的订阅数据:

    # subscription-manager refresh
    Copy to clipboard
  3. 列出可用的订阅:

    # subscription-manager list --available --matches '*pipelines*'
    Copy to clipboard
  4. 在上一命令的输出中,找到 OpenShift Container Platform 订阅的池 ID,并把订阅附加到注册的系统:

    # subscription-manager attach --pool=<pool_id>
    Copy to clipboard
  5. 启用 Red Hat OpenShift Pipelines 所需的仓库:

    • Linux (x86_64, amd64)

      # subscription-manager repos --enable="pipelines-1.18-for-rhel-8-x86_64-rpms"
      Copy to clipboard
    • Linux on IBM zSystems 和 IBM® LinuxONE (s390x)

      # subscription-manager repos --enable="pipelines-1.18-for-rhel-8-s390x-rpms"
      Copy to clipboard
    • Linux on IBM Power (ppc64le)

      # subscription-manager repos --enable="pipelines-1.18-for-rhel-8-ppc64le-rpms"
      Copy to clipboard
    • Linux on ARM (aarch64, arm64)

      # subscription-manager repos --enable="pipelines-1.18-for-rhel-8-aarch64-rpms"
      Copy to clipboard
  6. 安装 openshift-pipelines-client 软件包:

    # yum install openshift-pipelines-client
    Copy to clipboard

安装 CLI 后,就可以使用tkn命令:

$ tkn version
Copy to clipboard

1.3. 在 Windows 上安装 Red Hat OpenShift Pipelines CLI

对于 Windows,您可以将 CLI 下载为 zip 存档。

流程

  1. 下载 CLI 工具
  2. 使用 ZIP 程序解压存档。
  3. 将您的 tkn, tkn-pac, 和 opc 文件添加到 PATH 环境变量中。
  4. 要查看您的 PATH,请运行以下命令:

    C:\> path
    Copy to clipboard

1.4. 在 macOS 上安装 Red Hat OpenShift Pipelines CLI

对于 macOS,您可以将 CLI 下载为 tar.gz 存档。

流程

  1. 下载相关的 CLI 工具。

  2. 解包并提取存档。
  3. 将您的 tkn, tkn-pac, 和 opc 文件添加到 PATH 环境变量中。
  4. 要查看您的 PATH,请运行以下命令:

    $ echo $PATH
    Copy to clipboard

第 2 章 配置 OpenShift Pipelines tkn CLI

配置 Red Hat OpenShift Pipelines tkn CLI 以启用 tab 自动完成功能。

2.1. 启用 tab 自动完成功能

在安装tkn CLI,可以启用 tab 自动完成功能,以便在按 Tab 键时自动完成tkn命令或显示建议选项。

先决条件

  • 已安装tkn CLI。
  • 需要在本地系统中安装了 bash-completion

流程

以下过程为 Bash 启用 tab 自动完成功能。

  1. 将 Bash 完成代码保存到一个文件中:

    $ tkn completion bash > tkn_bash_completion
    Copy to clipboard
  2. 将文件复制到 /etc/bash_completion.d/

    $ sudo cp tkn_bash_completion /etc/bash_completion.d/
    Copy to clipboard

    您也可以将文件保存到一个本地目录,并从您的.bashrc文件中 source 这个文件。

开新终端时 tab 自动完成功能将被启用。

第 3 章 OpenShift Pipelines tkn 参考

本节列出了基本的 tkn CLI 命令。

3.1. 基本语法

tkn [command or options] [arguments…​]

3.2. 全局选项

--help, -h

3.3. 工具命令

3.3.1. tkn

tkn CLI 的主命令。

示例: 显示所有选项

$ tkn
Copy to clipboard

3.3.2. completion [shell]

输出 shell 完成代码,必须经过评估方可提供互动完成。支持的 shell 是 bashzsh

示例:bash shell 完成代码

$ tkn completion bash
Copy to clipboard

3.3.3. version

输出 tkn CLI 的版本信息。

示例: 检查 tkn 版本

$ tkn version
Copy to clipboard

3.4. Pipelines 管理命令

3.4.1. pipeline

管理管道。

示例: 显示帮助信息

$ tkn pipeline --help
Copy to clipboard

3.4.2. pipeline delete

删除管道。

示例:从命名空间中删除管道

$ tkn pipeline delete <pipeline_name> -n <namespace_name>
Copy to clipboard

3.4.3. pipeline describe

描述管道。

示例:描述管道

$ tkn pipeline describe <pipeline_name>
Copy to clipboard

3.4.4. pipeline list

显示管道列表。

示例:显示管道列表

$ tkn pipeline list
Copy to clipboard

3.4.5. pipeline logs

显示特定管道的日志。

示例:流管道的实时日志

$ tkn pipeline logs -f <pipeline_name>
Copy to clipboard

3.4.6. pipeline start

启动管道。

示例:启动管道

$ tkn pipeline start <pipeline_name>
Copy to clipboard

3.5. pipeline run 命令

3.5.1. pipelinerun

管理管道运行。

示例: 显示帮助信息

$ tkn pipelinerun -h
Copy to clipboard

3.5.2. pipelinerun cancel

取消管道运行。

示例:取消从命名空间中运行的管道

$ tkn pipelinerun cancel <pipeline_run_name> -n <namespace_name>
Copy to clipboard

3.5.3. pipelinerun delete

删除管道运行。

示例:删除管道从命名空间中运行

$ tkn pipelinerun delete <pipeline_run_name_1> <pipeline_run_name_2> -n <namespace_name>
Copy to clipboard

示例:删除所有管道从命名空间中运行,但最近执行的管道运行除外

$ tkn pipelinerun delete -n <namespace_name> --keep 5 1
Copy to clipboard

1
使用您要保留的最新执行的管道运行数量替换 5

示例:删除所有管道

$ tkn pipelinerun delete --all
Copy to clipboard

注意

从 Red Hat OpenShift Pipelines 1.6 开始,tkn pipelinerun delete --all 命令不会删除处于 running 状态的任何资源。

3.5.4. pipelinerun describe

描述管道运行。

示例:描述在命名空间中运行的管道

$ tkn pipelinerun describe <pipeline_run_name> -n <namespace_name>
Copy to clipboard

3.5.5. pipelinerun list

列出管道运行。

示例: 显示在命名空间中运行的管道列表

$ tkn pipelinerun list -n <namespace_name>
Copy to clipboard

3.5.6. pipelinerun logs

显示管道运行的日志。

示例:显示管道运行的日志,其中包含命名空间中的所有任务和步骤

$ tkn pipelinerun logs <pipeline_run_name> -a -n <namespace_name>
Copy to clipboard

3.6. 任务管理命令

3.6.1. task

管理任务。

示例: 显示帮助信息

$ tkn task -h
Copy to clipboard

3.6.2. task delete

删除任务。

示例:从命名空间中删除任务

$ tkn task delete <task_name_1> <task_name_2> -n <namespace_name>
Copy to clipboard

3.6.3. task describe

描述任务。

示例:描述命名空间中的任务

$ tkn task describe <task_name> -n <namespace_name>
Copy to clipboard

3.6.4. task list

列出任务。

示例: 列出命名空间中的所有任务

$ tkn task list -n <namespace_name>
Copy to clipboard

3.6.5. task start

启动一个任务。

示例: 启动命名空间中的任务

$ tkn task start <task_name> -s <service_account_name> -n <namespace_name>
Copy to clipboard

3.7. task run 命令

3.7.1. taskrun

管理任务运行。

示例: 显示帮助信息

$ tkn taskrun -h
Copy to clipboard

3.7.2. taskrun cancel

取消任务运行。

示例:取消从命名空间中运行的任务

$ tkn taskrun cancel <task_run_name> -n <namespace_name>
Copy to clipboard

3.7.3. taskrun delete

删除一个 TaskRun。

示例:删除从命名空间中运行的任务

$ tkn taskrun delete <task_run_name_1> <task_run_name_2> -n <namespace_name>
Copy to clipboard

示例:删除除五个最近执行的任务外从命名空间中运行的所有任务

$ tkn taskrun delete -n <namespace_name> --keep 5 1
Copy to clipboard

1
5 替换为您要保留的最新执行任务数量。

3.7.4. taskrun describe

描述任务运行。

示例:描述在命名空间中运行的任务

$ tkn taskrun describe <task_run_name> -n <namespace_name>
Copy to clipboard

3.7.5. taskrun list

列出任务运行。

示例:列出所有任务在命名空间中运行

$ tkn taskrun list -n <namespace_name>
Copy to clipboard

3.7.6. taskrun logs

显示任务运行日志.

示例:显示在命名空间中运行的任务的实时日志

$ tkn taskrun logs -f <task_run_name> -n <namespace_name>
Copy to clipboard

3.8. Pipeline 资源管理命令

3.8.1. resource

管理管道资源。

示例: 显示帮助信息

$ tkn resource -h
Copy to clipboard

3.8.2. resource create

创建一个 Pipeline 资源。

示例: 在命名空间中创建一个 Pipeline 资源

$ tkn resource create -n myspace
Copy to clipboard

这是一个交互式命令,它要求输入资源名称、资源类型以及基于资源类型的值。

3.8.3. resource delete

删除 Pipeline 资源。

示例:从命名空间中删除 myresource Pipeline 资源

$ tkn resource delete myresource -n myspace
Copy to clipboard

3.8.4. resource describe

描述管道资源。

示例:描述 myresource Pipeline 资源

$ tkn resource describe myresource -n myspace
Copy to clipboard

3.8.5. resource list

列出管道资源。

示例: 列出命名空间中的所有管道资源

$ tkn resource list -n myspace
Copy to clipboard

3.9. 触发器管理命令

3.9.1. eventlistener

管理 EventListeners。

示例: 显示帮助信息

$ tkn eventlistener -h
Copy to clipboard

3.9.2. eventlistener delete

删除一个 EventListener。

示例:删除命令空间中的 mylistener1mylistener2 EventListeners

$ tkn eventlistener delete mylistener1 mylistener2 -n myspace
Copy to clipboard

3.9.3. eventlistener describe

描述 EventListener。

示例:描述命名空间中的 mylistener EventListener

$ tkn eventlistener describe mylistener -n myspace
Copy to clipboard

3.9.4. eventlistener list

列出 EventListeners。

示例: 列出命名空间中的所有 EventListeners

$ tkn eventlistener list -n myspace
Copy to clipboard

3.9.5. eventListener 日志

显示 EventListener 的日志。

示例: 在一个命名空间中显示 mylistener EventListener 的日志

$ tkn eventlistener logs mylistener -n myspace
Copy to clipboard

3.9.6. triggerbinding

管理 TriggerBindings。

示例: 显示 TriggerBindings 帮助信息

$ tkn triggerbinding -h
Copy to clipboard

3.9.7. triggerbinding delete

删除 TriggerBinding。

示例:删除一个命名空间中的 mybinding1mybinding2 TriggerBindings

$ tkn triggerbinding delete mybinding1 mybinding2 -n myspace
Copy to clipboard

3.9.8. triggerbinding describe

描述 TriggerBinding。

示例:描述命名空间中的 mybinding TriggerBinding

$ tkn triggerbinding describe mybinding -n myspace
Copy to clipboard

3.9.9. triggerbinding list

列出 TriggerBindings。

示例: 列出命名空间中的所有 TriggerBindings

$ tkn triggerbinding list -n myspace
Copy to clipboard

3.9.10. triggertemplate

管理 TriggerTemplates。

示例: 显示 TriggerTemplate 帮助

$ tkn triggertemplate -h
Copy to clipboard

3.9.11. triggertemplate delete

删除 TriggerTemplate。

示例:删除命名空间中的 mytemplate1mytemplate2 TriggerTemplates

$ tkn triggertemplate delete mytemplate1 mytemplate2 -n `myspace`
Copy to clipboard

3.9.12. triggertemplate describe

描述 TriggerTemplate。

示例: 描述命名空间中的 mytemplate TriggerTemplate

$ tkn triggertemplate describe mytemplate -n `myspace`
Copy to clipboard

3.9.13. triggertemplate list

列出 TriggerTemplates。

示例: 列出命名空间中的所有 TriggerTemplates

$ tkn triggertemplate list -n myspace
Copy to clipboard

3.9.14. clustertriggerbinding

管理 ClusterTriggerBindings。

示例: 显示 ClusterTriggerBindings 帮助信息

$ tkn clustertriggerbinding -h
Copy to clipboard

3.9.15. clustertriggerbinding delete

删除 ClusterTriggerBinding。

示例: 删除 myclusterbinding1myclusterbinding2 ClusterTriggerBindings

$ tkn clustertriggerbinding delete myclusterbinding1 myclusterbinding2
Copy to clipboard

3.9.16. clustertriggerbinding describe

描述 ClusterTriggerBinding。

示例: 描述 myclusterbinding ClusterTriggerBinding

$ tkn clustertriggerbinding describe myclusterbinding
Copy to clipboard

3.9.17. clustertriggerbinding list

列出 ClusterTriggerBindings。

示例: 列出所有 ClusterTriggerBindings

$ tkn clustertriggerbinding list
Copy to clipboard

3.10. hub 互动命令

与 Tekton Hub 交互,以获取任务和管道等资源。

3.10.1. hub

与 hub 交互。

示例: 显示帮助信息

$ tkn hub -h
Copy to clipboard

示例:与 hub API 服务器交互

$ tkn hub --api-server https://api.hub.tekton.dev
Copy to clipboard

注意

对于每个示例,若要获取对应的子命令和标记,请运行 tkn hub <command> --help

3.10.2. hub downgrade

对一个安装的资源进行降级。

示例:将 mynamespace 命名空间中的 mytask 任务降级到它的较旧版本

$ tkn hub downgrade task mytask --to version -n mynamespace
Copy to clipboard

3.10.3. hub get

按名称、类型、目录和版本获取资源清单。

示例:从 tekton 目录中获取 myresource 管道或任务的特定版本的清单

$ tkn hub get [pipeline | task] myresource --from tekton --version version
Copy to clipboard

3.10.4. hub info

按名称、类型、目录和版本显示资源的信息。

示例:显示 tekton 目录中有关 mytask 任务的特定版本的信息

$ tkn hub info task mytask --from tekton --version version
Copy to clipboard

3.10.5. hub install

按类型、名称和版本从目录安装资源。

示例:从 mynamespace 命名空间中的 tekton 目录安装 mytask 任务的特定版本

$ tkn hub install task mytask --from tekton --version version -n mynamespace
Copy to clipboard

3.10.6. hub reinstall

按类型和名称重新安装资源。

示例:从 mynamespace 命名空间中的 tekton 目录重新安装 mytask 任务的特定版本

$ tkn hub reinstall task mytask --from tekton --version version -n mynamespace
Copy to clipboard

3.10.8. hub upgrade

升级已安装的资源。

示例:将 mynamespace 命名空间中安装的 mytask 任务升级到新版本

$ tkn hub upgrade task mytask --to version -n mynamespace
Copy to clipboard

法律通告

Copyright © 2025 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat, Inc.