-
Notifications
You must be signed in to change notification settings - Fork 0
Description
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
- JavaScript OR operator -
${{ parameters.x || 'default' }}
- ❌ Not evaluated - Nunjucks default filter - Not tested yet
- Config fallback helper - Generated correct output but still not evaluated
- 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
- Does Backstage's Nunjucks support JavaScript
||
operator in template expressions? - Is there a recommended way to provide config fallbacks for optional parameters?
- 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 sourceapp-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
Labels
Type
Projects
Status