如何根据用户是否提供了输入参数向步骤添加可选字段?我并不是在寻找要跳过的整个步骤,而只是在寻找一个参数。
在以下示例中,仅当用户从参数部分选择了其他协作者时,我才想在
collaborators
步骤中添加 publish:github
部分。
apiVersion: scaffolder.backstage.io/v1beta3
# https://backstage.io/docs/features/software-catalog/descriptor-format#kind-template
kind: Template
metadata:
name: example-nodejs-template
title: Example Node.js Template
description: An example template for the scaffolder that creates a simple Node.js service
spec:
owner: user:guest
type: service
# These parameters are used to generate the input form in the frontend, and are
# used to gather input data for the execution of the template.
parameters:
- title: Fill in some steps
required:
- name
properties:
name:
title: Name
type: string
description: Unique name of the component
ui:autofocus: true
ui:options:
rows: 5
collaborators:
title: Additional collaborators
type: string
description: Github team
ui:field: EntityPicker
ui:options:
orderable: false
catalogFilter:
- kind: [Group]
metadata.annotations.github.com/team-slug: { exists: true }
# These steps are executed in the scaffolder backend, using data that we gathered
# via the parameters above.
steps:
# Each step executes an action, in this case one templates files into the working directory.
- id: fetch-base
name: Fetch Base
action: fetch:template
input:
url: ./content
values:
name: ${{ parameters.name }}
# This step publishes the contents of the working directory to GitHub.
- id: publish
name: Publish
action: publish:github
input:
allowedHosts: ["github.com"]
description: This is the ${{ parameters.name }}.
repoUrl: github.com?repo=${{ parameters.name }}&owner=manuviswam
defaultBranch: main
collaborators:
- team: ${{ parameters.collaborators }}
access: admin
# The final step is to register our new component in the catalog.
- id: register
name: Register
action: catalog:register
input:
repoContentsUrl: ${{ steps['publish'].output.repoContentsUrl }}
catalogInfoPath: '/catalog-info.yaml'
# Outputs are displayed to the user after a successful execution of the template.
output:
links:
- title: Repository
url: ${{ steps['publish'].output.remoteUrl }}
- title: Open in catalog
icon: catalog
entityRef: ${{ steps['register'].output.entityRef }}
我尝试使用 Nunjucks if 条件如下,但它给了我一个 YAML 解析错误
- id: publish
name: Publish
action: publish:github
input:
allowedHosts: ["github.com"]
description: This is the ${{ parameters.name }}.
repoUrl: github.com?repo=${{ parameters.name }}&owner=manuviswam
defaultBranch: main
{% if parameters.collaborators %}
collaborators:
- team: ${{ parameters.collaborators }}
access: admin
{% endif %}