-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: Jinja2 template engine in workflow templates #4595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
korolenkowork
wants to merge
81
commits into
keephq:main
from
korolenkowork:feature/Jinja-template-engine-in-workflow-templates
Closed
Changes from all commits
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
db2aa45
v1
korolenkowork 9dfe5f5
Update iohandler.py
korolenkowork 434148b
Update iohandler.py
korolenkowork ee381d7
fix
korolenkowork 1cc0d29
Done
korolenkowork e00dd59
Update iohandler.py
korolenkowork 255ec99
Docs
korolenkowork d11b74c
Update overview.mdx
korolenkowork 04d8f61
Remove useless
korolenkowork 73eee00
Fix
korolenkowork 5ff14ff
catch template syntax error
korolenkowork 31541a8
Fix dependencies
korolenkowork 4e41b40
Update poetry.lock
korolenkowork 41a0ce2
Fix global missing keys
korolenkowork 2ab9717
Return quote func :D
korolenkowork 586c332
Fix
korolenkowork ff8befb
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork 0910b1f
Keep trailing new line jinja
korolenkowork da3ef36
IOHandeler mustache and jinja2 both support
korolenkowork 75a2176
Fix for ruff lint :D
korolenkowork cd3b1ed
Workflow parse templating
korolenkowork 97aac08
Update iohandler.py
korolenkowork f38c903
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork b656cfe
fix jinja tests
korolenkowork df6fd52
Merge branch 'feature/Jinja-template-engine-in-workflow-templates' ofβ¦
korolenkowork f4394a4
test jinja default templating engine
korolenkowork c67e7b0
test for syntax validator
korolenkowork d9f40c4
Docs
korolenkowork e9a8fbe
Parser tests
korolenkowork f1d6224
Test workflow
korolenkowork 63d8eb3
minor
korolenkowork 7860eba
More test in honor of the God of Tests
korolenkowork 59428ee
test fix
korolenkowork ae35db9
Minor revert
korolenkowork 813fad7
Workflow test
korolenkowork f6aafc8
fix
korolenkowork 98ee2da
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork 219de65
minor
korolenkowork 223debd
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
shahargl 23ec014
IOValidatorMixin
korolenkowork 0044d96
Separate IOHandler
korolenkowork 60c9225
Rewrite render recursively
korolenkowork 0921f60
Change workflow iohandler definition
korolenkowork 669f4ce
fix tests
korolenkowork cc2cbd4
fix iohanler tests
korolenkowork 9d4959f
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork 0738c48
fix
korolenkowork 744d0f6
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork 9d5fa47
fix
korolenkowork c5d9ca4
minor
korolenkowork 0117994
minor
korolenkowork 0654283
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork c5c7aab
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork 97e5bfa
Update poetry.lock
korolenkowork 7de5227
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork 40e6c8e
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
skynetigor 9b7950d
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork c2cd70c
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork 1d06dfd
Update templating.mdx
korolenkowork ef38522
Update mint.json
korolenkowork 1ae9614
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork fe36005
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork ccdc67a
Post rev changes
korolenkowork c0bdb22
Simplify IOValidatorMixin
korolenkowork 686b9fd
More tests in honor of God of Tests
korolenkowork 5152b23
Remove Jinja2 comments logic
korolenkowork 5435fa5
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork 9e3a99a
Update poetry lock
korolenkowork 9645a28
test
korolenkowork 9a5f3df
fix
korolenkowork fc80e28
fix test
korolenkowork 9195cc8
fix
korolenkowork 10e49f5
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
talboren 267af1b
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork 67ceb08
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork eefd491
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork 1471025
Update test_iohandler.py
korolenkowork 98cebc9
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork 08e4b8f
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
korolenkowork 225d43c
Update poetry.lock
korolenkowork 58f0d0a
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-teβ¦
shahargl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| --- | ||
| title: Templating | ||
| --- | ||
|
|
||
| Keep supports two templating engines for dynamic values inside workflow YAML definitions: | ||
|
|
||
| - Jinja2 β powerful and Pythonic | ||
| - Mustache β simple and logic-less | ||
|
|
||
| You can select the templating engine by setting the templating parameter in your YAML workflow. By default, Keep uses Mustache. | ||
|
|
||
| ## π Switching Between Engines | ||
|
|
||
| Set the templating mode at the top of your workflow: | ||
|
|
||
| - Default (no need to specify): mustache | ||
| - To use Jinja2: add templating: jinja2 | ||
|
|
||
| Example: | ||
|
|
||
| ```yaml | ||
| workflows: | ||
| - id: jiraonprem-investigate | ||
| name: Create investigation | ||
| templating: mustache | ||
| actions: | ||
| ... | ||
| ``` | ||
|
|
||
| or | ||
|
|
||
| ```yaml | ||
| workflows: | ||
| - id: jiraonprem-investigate | ||
| name: Create investigation | ||
| templating: jinja2 | ||
| actions: | ||
| ... | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Mustache Syntax (Default) | ||
|
|
||
| Mustache uses double curly braces for variable interpolation and does not support logic like if/else. | ||
|
|
||
| ### Variables | ||
| ```mustache | ||
| {{ alert.alertname }} | ||
| {{ alert.annotations.summary }} | ||
| {{ alert.generatorURL }} | ||
| ``` | ||
|
|
||
| ### Sections (conditionally rendered if value exists) | ||
| ```mustache | ||
| {{#alert.channel}} | ||
| *Channel:* {{ alert.channel }} | ||
| {{/alert.channel}} | ||
| ``` | ||
|
|
||
| ### Inverted Sections (rendered if value is missing or false) | ||
| ```mustache | ||
| {{^alert.alertgroup}} | ||
| *Alertgroup:* None | ||
| {{/alert.alertgroup}} | ||
| ``` | ||
|
|
||
| [See more in the docs](https://github.com/noahmorrison/chevron) | ||
|
|
||
| ## π§ Jinja2 Syntax | ||
|
|
||
| Jinja2 provides more advanced capabilities including conditionals, filters, and logic. | ||
|
|
||
| Set: | ||
| ```yaml | ||
| templating: jinja2 | ||
| ``` | ||
|
|
||
| ### Variables | ||
| ```jinja2 | ||
| {{ alert.alertname }} | ||
| {{ alert.annotations.summary }} | ||
| ``` | ||
|
|
||
| ### Conditionals | ||
| ```jinja2 | ||
| {% if alert.channel %} | ||
| *Channel:* {{ alert.channel }} | ||
| {% endif %} | ||
| ``` | ||
|
|
||
| ### Default Values | ||
| ```jinja2 | ||
| {{ alert.alertgroup or 'None' }} | ||
| ``` | ||
|
|
||
| ### Filters | ||
| ```jinja2 | ||
| {{ alert.labels | join(', ') }} | ||
| {{ alert.cluster | default('Unknown Cluster') }} | ||
| ``` | ||
|
|
||
| [See more in the docs](https://jinja.palletsprojects.com/en/stable/) | ||
|
|
||
| ## π¦ Example: JiraOnPrem with Mustache (Default) | ||
|
|
||
| ```yaml | ||
| workflows: | ||
| - id: jiraonprem-investigate | ||
| name: Create investigation | ||
| templating: mustache | ||
| actions: | ||
| - name: jiraonprem-action | ||
| provider: | ||
| type: jiraonprem | ||
| config: "{{ providers.jiraOnPrem }}" | ||
| with: | ||
| description: | | ||
| *Alertname:* {{ alert.alertname }} | ||
| *Summary:* {{ alert.annotations.summary }} | ||
| {{#alert.channel}} | ||
| *Channel:* {{ alert.channel }} | ||
| {{/alert.channel}} | ||
| {{#alert.annotations.runbook_url}} | ||
| Runbook: [Runbook|{{ alert.annotations.runbook_url }}] | ||
| {{/alert.annotations.runbook_url}} | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
| ## π¦ Example: JiraOnPrem with Jinja2 | ||
|
|
||
| ```yaml | ||
| templating: jinja2 | ||
|
|
||
| workflows: | ||
| - id: jiraonprem-investigate | ||
| name: Create investigation | ||
| templating: jinja2 | ||
| actions: | ||
| - name: jiraonprem-action | ||
| provider: | ||
| type: jiraonprem | ||
| config: "{{ providers.jiraOnPrem }}" | ||
| with: | ||
| description: | | ||
| *Alertname:* {{ alert.alertname }} | ||
| *Summary:* {{ alert.annotations.summary }} | ||
| {% if alert.channel %} | ||
| *Channel:* {{ alert.channel }} | ||
| {% endif %} | ||
| {% if alert.annotations.runbook_url %} | ||
| Runbook: [Runbook|{{ alert.annotations.runbook_url }}] | ||
| {% endif %} | ||
| ``` | ||
|
|
||
|
|
||
| ## β Best Practices | ||
|
|
||
| - Use mustache for simple output formatting. | ||
| - Use jinja2 if you need conditions, defaults, or filters. | ||
| - Always wrap multiline strings with quotes and indent properly in YAML. | ||
| - In Jinja2, use `{% if %}` to check for presence of values. | ||
| - In Mustache, use `{{#section}}` and `{{^section}}` for presence/absence. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.