Skip to content

Backstage template expressions with fallback operators not evaluated #110

@felixboehm

Description

@felixboehm

Problem

Backstage's Nunjucks template engine does not evaluate ${{ }} expressions containing JavaScript || (OR) operators when used for config fallbacks in template steps.

Expected Behavior

Template expressions with fallback values should be evaluated at runtime:

repoUrl: github.com?owner=${{ parameters.gitopsOwner || 'open-service-portal' }}

Expected evaluation (when parameter undefined):

github.com?owner=open-service-portal

Actual Behavior

The expression is passed as a literal string to the scaffolder action:

Error: No token available for host: github.com, with owner ${{ parameters.gitopsOwner || 'open-service-portal' }}

The ${{ }} expression is not evaluated by Backstage's Nunjucks engine.

Context

  • Use Case: GitOps workflow template that should work with OR without parameter customization
  • Goal: Allow users to override GitOps repo via parameters, but fall back to app-config defaults if not provided
  • Current Workaround: Using config values directly during template generation (no parameter override support)

Attempted Solutions

  1. JavaScript OR operator - ${{ parameters.x || 'default' }} - ❌ Not evaluated
  2. Nunjucks default filter - Not tested yet
  3. Config fallback helper - Generated correct output but still not evaluated
  4. Quoted strings - No effect on evaluation

Template Generation Details

Transform Phase (Handlebars):

repoUrl: github.com?owner={{{backstageConfigFallback "parameters.gitopsOwner" config.gitops.owner}}}

Generated Template (What Backstage receives):

repoUrl: github.com?owner=${{ parameters.gitopsOwner || 'open-service-portal' }}

Runtime (What should happen):

  • Nunjucks evaluates ${{ }} expressions
  • JavaScript OR operator returns parameter value or fallback
  • Action receives: github.com?owner=open-service-portal

Runtime (What actually happens):

  • Expression not evaluated
  • Action receives literal: ${{ parameters.gitopsOwner || 'open-service-portal' }}
  • Action fails to parse

Questions

  1. Does Backstage's Nunjucks support JavaScript || operator in template expressions?
  2. Is there a recommended way to provide config fallbacks for optional parameters?
  3. Should we use Nunjucks default filter instead: ${{ parameters.x | default('value') }}?

Environment

  • Backstage Version: 1.42.0
  • Plugin: Custom XRD transform generating Template entities
  • Template API: scaffolder.backstage.io/v1beta3

Current Workaround

Using config values directly without parameter fallback:

repoUrl: github.com?owner=open-service-portal&repo=catalog-orders

This works but removes the ability for users to override via parameters.

Related Files

  • app-portal/plugins/ingestor/templates/steps/gitops.hbs - Template source
  • app-portal/app-config/ingestor.yaml - Config values

Desired Solution

Support for parameter fallbacks in one of these ways:

Option A: Support || operator

value: ${{ parameters.x || 'default' }}

Option B: Nunjucks default filter

value: ${{ parameters.x | default('default') }}

Option C: Separate fallback syntax

value: ${{ parameters.x }}
valueFallback: 'default'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions