This documentation is for a release that is no longer maintained
See documentation for the latest supported version.7.2. 创建模板作为 YAML 文件
您可以通过将 Template
对象定义为 YAML 文件来创建模板。
Template
对象描述了模板及其元数据。它还包含必要的输入变量以及由 scaffolding 服务执行的操作列表。
模板
对象示例
apiVersion: scaffolder.backstage.io/v1beta3 kind: Template metadata: name: template-name title: Example template description: An example template for v1beta3 scaffolder. spec: owner: backstage/techdocs-core type: service parameters: - title: Fill in some steps required: - name properties: name: title: Name type: string description: Unique name of the component owner: title: Owner type: string description: Owner of the component - title: Choose a location required: - repoUrl properties: repoUrl: title: Repository Location type: string steps: - id: fetch-base name: Fetch Base action: fetch:template # ... output: links: - title: Repository url: ${{ steps['publish'].output.remoteUrl }} - title: Open in catalog icon: catalog entityRef: ${{ steps['register'].output.entityRef }} # ...
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
name: template-name
title: Example template
description: An example template for v1beta3 scaffolder.
spec:
owner: backstage/techdocs-core
type: service
parameters:
- title: Fill in some steps
required:
- name
properties:
name:
title: Name
type: string
description: Unique name of the component
owner:
title: Owner
type: string
description: Owner of the component
- title: Choose a location
required:
- repoUrl
properties:
repoUrl:
title: Repository Location
type: string
steps:
- id: fetch-base
name: Fetch Base
action: fetch:template
# ...
output:
links:
- title: Repository
url: ${{ steps['publish'].output.remoteUrl }}
- title: Open in catalog
icon: catalog
entityRef: ${{ steps['register'].output.entityRef }}
# ...
- 1
- 指定模板的名称。
- 2
- 指定模板的标题。这是在 Create… 视图中的模板标题上可见的标题。
- 3
- 指定模板的描述。这是在 Create… view 中的模板标题上可见的描述。
- 4
- 指定模板的所有权。
owner
字段提供有关负责维护或监督系统或机构中模板的信息。在提供的示例中,owner
字段设置为backstage/busybox-core
。这意味着此模板属于backstage
命名空间中的 zFCP-core
项目。 - 5
- 指定组件类型。此必填字段接受任何字符串值,但您的组织应为其建立正确的税款。Red Hat Developer Hub 实例可能会读取此字段,并根据它的值的不同行为。例如,
Web 站点
类型组件可能会在特定于 Web 站点的 Red Hat Developer Hub 界面中显示工具。此字段通常有以下值:
service
- 后端服务,通常是公开 API。
网站
- 网站。
程序库
- 软件库,如 npm 模块或 Java 库。
- 6
- 当用户使用 Red Hat Developer Hub 控制台中的模板创建组件时,使用
parameters
部分为用户输入指定参数。每个参数
子部分由标题和属性定义,创建一个具有该定义的新表单页面。 - 7
- 使用
steps
部分指定后端中执行的步骤。这些步骤必须通过使用唯一的步骤 ID、名称和操作来定义。您可以通过访问 URLhttps://<rhdh_url>/create/actions
来查看 Red Hat Developer Hub 实例上可用的操作。 - 8
- 使用
output
部分指定使用模板时创建的输出数据的结构。output
部分(特别是links
子部分)为用户提供了可用于访问和与从模板创建的组件交互的宝贵引用和 URL。 - 9
- 提供与生成组件关联的存储库的引用或 URL。
- 10
- 提供允许用户在列出各种组件的目录或目录中打开生成的组件的参考或 URL。