Download File to Workspace

Action ID: fetch:template:file
NPM Package:

@backstage/plugin-scaffolder-backend

Description

Downloads single file and places it in the workspace.

Input Schema

PropertyTypeDescriptionRequired
urlstringRelative path or absolute URL pointing to the single file to fetch.
tokenstringAn optional token to use for authentication when reading the resources.
valuesobjectValues to pass on to the templating engine
replacebooleanIf set, replace file in targetPath instead of overwriting existing one.
targetPathstringTarget path within the working directory to download the file as.
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.
cookiecutterCompatbooleanEnable features to maximise compatibility with templates built for fetch:cookiecutter

Output Schema

No output schema defined for this action.

Usage Examples

Add a LICENSE from a private standards repository

Downloads a templated LICENSE file from a private repository and renders year and holder. Use this after fetching a base project with fetch:template and before publishing with publish:github.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: https://github.com/acme-corp/templates/service
      values:
        name: ${{ parameters.name }}

  - id: add-license
    action: fetch:template:file
    input:
      url: https://raw.githubusercontent.com/acme-corp/engineering-standards/main/licenses/apache-2.0.hbs
      targetPath: LICENSE
      values:
        year: ${{ parameters.licenseYear }}
        holder: ${{ parameters.owner }}
      trimBlocks: true
      lstripBlocks: true
      token: ${{ parameters.githubAccessToken }}

  - id: publish
    action: publish:github
    input:
      repoUrl: github.com?owner=${{ parameters.owner }}&repo=${{ parameters.name }}

Install a GitHub Actions workflow with cookiecutter compatibility

Fetches a CI workflow file that uses cookiecutter-style variables and renders it with provided values. Use when reusing a centralized workflow template while keeping whitespace tidy.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: https://github.com/acme-corp/templates/node-service
      values:
        name: ${{ parameters.name }}

  - id: ci-workflow
    action: fetch:template:file
    input:
      url: https://raw.githubusercontent.com/acme-corp/ci-templates/main/github-actions/node-ci.yml.j2
      targetPath: .github/workflows/ci.yml
      values:
        repo_name: ${{ parameters.name }}
        default_branch: ${{ parameters.defaultBranch }}
        node_version: "20.x"
      cookiecutterCompat: true
      trimBlocks: true
      lstripBlocks: true

  - id: publish
    action: publish:github
    input:
      repoUrl: github.com?owner=${{ parameters.owner }}&repo=${{ parameters.name }}

Replace an existing Dockerfile with a templated version

Replaces an existing Dockerfile in the workspace with a rendered template from a shared repository. Use when the base template includes a placeholder that you want to swap with a standardized image definition.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: https://github.com/acme-corp/templates/service
      values:
        name: ${{ parameters.name }}

  - id: dockerfile
    action: fetch:template:file
    input:
      url: https://raw.githubusercontent.com/acme-corp/dockerfiles/main/node/Dockerfile.njk
      targetPath: Dockerfile
      values:
        app_name: ${{ parameters.name }}
        node_version: "20-alpine"
        app_port: ${{ parameters.port }}
      replace: true

  - id: publish
    action: publish:github
    input:
      repoUrl: github.com?owner=${{ parameters.owner }}&repo=${{ parameters.name }}

Generate an environment-specific Kubernetes manifest

Downloads a deployment manifest and renders environment-specific values, writing to an env-scoped path. Use when creating separate manifests for dev, staging, and prod.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: https://github.com/acme-corp/templates/service
      values:
        name: ${{ parameters.name }}

  - id: k8s-deployment
    action: fetch:template:file
    input:
      url: https://raw.githubusercontent.com/acme-corp/platform-templates/main/k8s/deployment.yaml.njk
      targetPath: deploy/k8s/${{ parameters.environment }}/deployment.yaml
      values:
        appName: ${{ parameters.name }}
        namespace: ${{ parameters.namespace }}
        image: ghcr.io/acme-corp/${{ parameters.name }}:${{ parameters.imageTag }}
        replicas: ${{ parameters.replicas }}
      trimBlocks: true
      lstripBlocks: true

  - id: publish
    action: publish:github
    input:
      repoUrl: github.com?owner=${{ parameters.owner }}&repo=${{ parameters.name }}

Copy a shared .editorconfig from the current template repository

Uses a relative path to bring in a shared configuration file that is stored alongside the template source. Use when you want to reuse a file from the same template repo without another fetch.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: https://github.com/acme-corp/templates/service
      values:
        name: ${{ parameters.name }}

  - id: editorconfig
    action: fetch:template:file
    input:
      url: ./partials/.editorconfig
      targetPath: .editorconfig

  - id: publish
    action: publish:github
    input:
      repoUrl: github.com?owner=${{ parameters.owner }}&repo=${{ parameters.name }}

Other actions in @backstage/plugin-scaffolder-backend