Fetch And Template Files

Action ID: fetch:template
NPM Package:

@backstage/plugin-scaffolder-backend

Description

Downloads a skeleton, templates variables into it, and places the result in the workspace, or in a subdirectory.

Input Schema

PropertyTypeDescriptionRequired
urlstringRelative path or absolute URL pointing to the directory tree to fetch
tokenstringAn optional token to use for authentication when reading the resources.
valuesobjectValues to pass on to the templating engine
replacebooleanIf set, replace files in targetPath instead of skipping existing ones.
targetPathstringTarget path within the working directory to download the contents to. Defaults to the working directory root.
trimBlocksbooleanIf set, the first newline after a block is removed (block, not variable tag).
lstripBlocksbooleanIf set, leading spaces and tabs are stripped from the start of a line to a block.
copyWithoutRenderarrayAn array of glob patterns. Any files or directories which match are copied without being processed as templates.
cookiecutterCompatbooleanEnable features to maximise compatibility with templates built for fetch:cookiecutter
copyWithoutTemplatingarrayAn array of glob patterns. Contents of matched files or directories are copied without being processed, but paths are subject to rendering.
templateFileExtensionanyIf set, only files with the given extension will be templated. If set to `true`, the default extension `.njk` is used.

Output Schema

No output schema defined for this action.

Usage Examples

Fetch a Node service template from GitHub and publish to GitHub

Fetches a Node service skeleton from a GitHub repository, renders variables, and then publishes the generated code to a new GitHub repo using publish:github.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: https://github.com/acme-org/software-templates/tree/main/skeletons/node-service
      values:
        component_id: ${{ parameters.component_id }}
        owner: ${{ parameters.owner }}
        description: ${{ parameters.description }}
        system: payments
        port: 8080

  - id: publish
    action: publish:github
    input:
      repoUrl: github.com?owner=acme-org&repo=${{ parameters.component_id }}
      defaultBranch: main

Fetch into a subdirectory with controlled templating and publish to GitLab

Downloads a Java Spring skeleton into a subdirectory, skips rendering for binary and static assets, trims template whitespace, and then publishes to GitLab using publish:gitlab.

Copy
steps:
  - id: fetch-into-dir
    action: fetch:template
    input:
      url: https://gitlab.com/acme/templates/java-spring/-/tree/main/skeleton
      targetPath: services/${{ parameters.component_id }}
      values:
        component_id: ${{ parameters.component_id }}
        owner: ${{ parameters.owner }}
        java_package: com.acme.payments
        port: 8081
      copyWithoutRender:
        - '**/*.png'
        - '**/*.jar'
        - 'static/**'
      trimBlocks: true
      lstripBlocks: true

  - id: publish
    action: publish:gitlab
    input:
      repoUrl: gitlab.com?owner=acme&repo=${{ parameters.component_id }}
      defaultBranch: main

Use Cookiecutter compatibility to scaffold from a Cookiecutter template

Fetches a Cookiecutter-based template and renders it with Cookiecutter-compatible features enabled. Useful when reusing existing Cookiecutter templates, then publishing with publish:github.

Copy
steps:
  - id: fetch-cookiecutter
    action: fetch:template
    input:
      url: https://github.com/cookiecutter/cookiecutter-django
      cookiecutterCompat: true
      targetPath: services/${{ parameters.component_id }}
      values:
        project_slug: ${{ parameters.component_id }}
        project_name: ${{ parameters.name }}
        author_name: ${{ parameters.owner }}
        email: [email protected]
        timezone: UTC
        debug: 'n'

  - id: publish
    action: publish:github
    input:
      repoUrl: github.com?owner=acme-org&repo=${{ parameters.component_id }}
      defaultBranch: main

Template only .njk files and skip templating in a Helm chart

Only files with the .njk extension are rendered while Helm chart contents are copied verbatim but filenames are still templated. Existing files in the target path are replaced and the result can then be published with publish:github.

Copy
steps:
  - id: fetch-partial-templating
    action: fetch:template
    input:
      url: https://github.com/acme-org/templates/tree/main/skeletons/service-with-helm
      targetPath: ${{ parameters.component_id }}
      templateFileExtension: true
      copyWithoutTemplating:
        - 'charts/**'
        - '**/*.min.js'
      values:
        component_id: ${{ parameters.component_id }}
        owner: ${{ parameters.owner }}
        container_image: ghcr.io/acme/${{ parameters.component_id }}:latest
      replace: true

  - id: publish
    action: publish:github
    input:
      repoUrl: github.com?owner=acme-org&repo=${{ parameters.component_id }}
      defaultBranch: main

Fetch from a private GitHub Enterprise repo using a token

Downloads a Go service skeleton from a private GitHub Enterprise repository using a token, renders variables, and publishes to the same host with publish:github.

Copy
steps:
  - id: fetch-private
    action: fetch:template
    input:
      url: https://github.mycompany.com/platform/templates/tree/main/skeletons/go-service
      targetPath: services/${{ parameters.component_id }}
      token: ${{ secrets.gheToken }}
      values:
        component_id: ${{ parameters.component_id }}
        owner: ${{ parameters.owner }}
        description: ${{ parameters.description }}
        go_module: github.mycompany.com/acme/${{ parameters.component_id }}
        port: 9090

  - id: publish
    action: publish:github
    input:
      repoUrl: github.mycompany.com?owner=acme&repo=${{ parameters.component_id }}
      defaultBranch: main

Other actions in @backstage/plugin-scaffolder-backend