Render Workspace Templates

Action ID: workspace:template
NPM Package:

@backstage/plugin-scaffolder-backend

Description

Templates variables into file and directory names and content in the action context workspace.

Input Schema

PropertyTypeDescriptionRequired
valuesobject-
replaceboolean-
sourcePathstring-
targetPathstring-
cookiecutterCompatboolean-
copyWithoutTemplatingarray-
templateFileExtensionstring-

Output Schema

No output schema defined for this action.

Usage Examples

Render a service skeleton into a target folder

Templates the files in a skeleton directory using parameters from the form and writes the result to a service-specific folder. Use when you have a workspace skeleton and want to generate a new service instance.

Copy
steps:
  - id: render-service
    action: workspace:template
    input:
      sourcePath: ./skeleton
      targetPath: ./services/${{ parameters.name }}
      values:
        name: ${{ parameters.name }}
        owner: ${{ parameters.owner }}
        description: ${{ parameters.description }}
        port: ${{ parameters.port }}
      copyWithoutTemplating:
        - .git/**          # keep any VCS metadata untouched if present
        - assets/**        # static assets
        - "**/*.png"       # binaries
      templateFileExtension: .njk

Migrate a Cookiecutter template with compatibility mode

Processes a Cookiecutter-style template in the workspace and outputs a rendered project. Use when converting an existing Cookiecutter template.

Copy
steps:
  - id: cookiecutter-compat
    action: workspace:template
    input:
      sourcePath: ./cookiecutter-template
      targetPath: ./generated/${{ parameters.project_slug }}
      values:
        project_slug: ${{ parameters.project_slug }}
        module_name: ${{ parameters.moduleName }}
        author_name: ${{ parameters.author }}
        license: ${{ parameters.license }}
      copyWithoutTemplating:
        - hooks/**         # cookiecutter hook scripts
        - "**/*.ico"
      cookiecutterCompat: true

Re-render into an existing target with replace enabled

Overwrites an existing generated folder with updated values. Use when re-running scaffolding to refresh files.

Copy
steps:
  - id: rerender-overwrite
    action: workspace:template
    input:
      sourcePath: ./templates/service
      targetPath: ./output/${{ parameters.serviceId }}
      values:
        serviceId: ${{ parameters.serviceId }}
        image: ${{ parameters.containerImage }}
        replicas: ${{ parameters.replicas }}
      copyWithoutTemplating:
        - node_modules/**  # skip templating third-party code
        - ".git/**"
      replace: true

Render only Handlebars files and leave others untouched

Limits templating to .hbs files so other files are copied as-is. Use when only specific files need variable substitution.

Copy
steps:
  - id: render-hbs-only
    action: workspace:template
    input:
      sourcePath: ./handlebars-template
      targetPath: ./services/${{ parameters.name }}
      values:
        name: ${{ parameters.name }}
        org: ${{ parameters.org }}
        ci: ${{ parameters.ciProvider }}
      copyWithoutTemplating:
        - public/**        # static site content
        - "**/*.svg"
      templateFileExtension: .hbs

Generate service docs from a docs template

Renders a docs template into a service docs folder while skipping images. Use when producing README and mkdocs config alongside a service.

Copy
steps:
  - id: render-docs
    action: workspace:template
    input:
      sourcePath: ./docs-template
      targetPath: ./services/${{ parameters.name }}/docs
      values:
        docTitle: ${{ parameters.name }} Service
        serviceName: ${{ parameters.name }}
        owner: ${{ parameters.owner }}
        backstageEntityRef: ${{ parameters.owner }}/service/${{ parameters.name }}
      copyWithoutTemplating:
        - images/**
        - "**/*.gif"
      templateFileExtension: .njk

Other actions in @backstage/plugin-scaffolder-backend