scaffolder: Support conditional if on output links and text (#33332)
* Add sample template for conditional output demo Add a scaffolder template that exercises conditional `if` on output links and text items, for testing issue #24805. Signed-off-by: Dmitry Gusev <gusevda90@gmail.com> * Support conditional `if` on scaffolder output links and text Add `if` property to output link and text items in scaffolder templates, allowing template authors to conditionally show/hide output items based on parameters or step results. Items with a falsy `if` condition are filtered out before being sent to the frontend. Signed-off-by: Dmitry Gusev <gusevda90@gmail.com> * Add changesets for conditional output feature Signed-off-by: Dmitry Gusev <gusevda90@gmail.com> * Document conditional if on output links and text Signed-off-by: Dmitry Gusev <gusevda90@gmail.com> * Guard against non-object items in output arrays Signed-off-by: Dmitry Gusev <gusevda90@gmail.com> * Skip array items in output if-filtering destructuring Add Array.isArray guard to prevent corrupting array items into plain objects during the rest-destructuring step. Signed-off-by: Dmitry Gusev <gusevda90@gmail.com> * Extract filterConditionalItems helper to deduplicate logic Signed-off-by: Dmitry Gusev <gusevda90@gmail.com> * Align output if schema descriptions with step if semantics Signed-off-by: Dmitry Gusev <gusevda90@gmail.com> * Fix docs quality check: replace 'falsy' wording Signed-off-by: Dmitry Gusev <gusevda90@gmail.com> * Refactor filterConditionalItems to use flatMap and generics Replace .filter().map() with a single flatMap call and make the function generic to eliminate JsonArray casts at call sites. Signed-off-by: Dmitry Gusev <gusevda90@gmail.com> --------- Signed-off-by: Dmitry Gusev <gusevda90@gmail.com>
This commit is contained in:
@@ -767,6 +767,26 @@ output:
|
||||
**Entity URL:** `${{ steps['publish'].output.remoteUrl }}`
|
||||
```
|
||||
|
||||
Output `links` and `text` items support an optional `if` condition, using the same syntax as step conditions. Items where the condition evaluates to false are excluded from the output:
|
||||
|
||||
```yaml
|
||||
output:
|
||||
links:
|
||||
- title: Repository
|
||||
url: ${{ steps['publish'].output.remoteUrl }}
|
||||
- if: ${{ parameters.enableCI === "Yes" }}
|
||||
title: CI Dashboard
|
||||
url: https://ci.example.com/${{ parameters.name }}
|
||||
text:
|
||||
- title: Summary
|
||||
content: |
|
||||
**Component:** `${{ parameters.name }}`
|
||||
- if: ${{ parameters.showDetails }}
|
||||
title: Details
|
||||
content: |
|
||||
**CI enabled:** ${{ parameters.enableCI }}
|
||||
```
|
||||
|
||||
## The templating syntax
|
||||
|
||||
You might have noticed expressions wrapped in `${{ }}` in the examples. These are
|
||||
|
||||
Reference in New Issue
Block a user