id: dbt-slim-ci-with-manifest-promotion
namespace: company.team
description: |
dbt Core slim CI on Kestra. A `main` run builds the production branch and, only when the build is green, promotes
`target/manifest.json` to the KV Store with a pointer record (git sha, dbt version, time). Promotion is an explicit
`kv.Set` after the build, not the dbt plugin's `storeManifest`, because `storeManifest` writes the manifest to KV even
when dbt exits non-zero, which would make a red production build the baseline of every following pull request. A `pr` run loads that manifest and builds `state:modified+` with `--defer --favor-state`, so a
pull request only builds and tests what it changed; with no promoted manifest yet it falls back to a full build and
says so. Every outcome names the dbt nodes, not just "dbt failed".
labels:
team: data
purpose: dbt-ci
inputs:
- id: mode
type: SELECT
values: [ pr, main ]
defaults: pr
description: |
pr (default) builds `git_ref` against the promoted production manifest and never promotes. main builds
`production_branch` in full and promotes its manifest when every node succeeds. A GitHub push webhook overrides
this: the pushed branch decides (`production_branch` means main, anything else means pr).
- id: git_url
type: STRING
defaults: https://github.com/kestra-io/dbt-example
description: Repository that holds the dbt project. Public here; add
`username`/`password` to the two Clone tasks for a private one.
- id: git_ref
type: STRING
defaults: main
description: Branch built by a pr run (the pull request head). Ignored by a main
run, which always builds `production_branch`. `complex-dag` is a branch of
the sample repository that adds eleven models on top of `main`.
- id: git_commit
type: STRING
defaults: ""
description: Optional commit sha (7 to 40 hex characters) checked out instead of
the branch, for a pinned pull request head or to reproduce a past run.
Applies to both modes; a main run with a commit promotes that commit.
- id: production_branch
type: STRING
defaults: main
description: Branch that defines production. A main run clones it; a webhook
push to it is treated as a main run.
- id: project_dir
type: STRING
defaults: "."
description: Directory of `dbt_project.yml` inside the repository, relative, no
`..`. The sample repository keeps it at the root on `main` and under
`dbt/` on `master`.
- id: dbt_profile
type: STRING
defaults: my_dbt_project
description: Must equal the `profile` key of `dbt_project.yml`. The flow writes
a DuckDB `profiles.yml` under this name with two outputs, `prod` and `ci`,
as two schemas of one database file.
- id: dbt_target
type: STRING
defaults: ""
description: dbt target of this run. Empty picks `prod` for main and `ci` for
pr, which keeps a pull request from writing over production tables.
- id: duckdb_path
type: STRING
defaults: dbt_slim_ci.duckdb
description: |
DuckDB file both targets write to. Relative paths live in the task working directory and vanish with it, which is
enough to demonstrate selection. For `--defer` to resolve an unmodified upstream model to its production table the
pr run must see the main run's tables: give an absolute path on a volume both runs mount, or `md:<database>`
for MotherDuck, or replace the profile with your warehouse adapter.
- id: manifest_key
type: STRING
defaults: dbt_prod_manifest
description: KV key of the promoted manifest. The pointer record is stored under
`<manifest_key>_meta`, the last failure under
`<manifest_key>_last_failure`. One key pair per dbt project.
- id: kestra_api_url
type: STRING
defaults: http://localhost:8080
description: Base URL of this Kestra instance, used only to build the execution
link in messages when `kestra.url` is not configured.
variables:
tenant: main
ci_target_path: target_ci
slim_flags: --select state:modified+ --defer --state target --favor-state
checks:
- when: "{{ {'c': inputs.git_commit} | jq('.c | test(\"^([0-9a-f]{7,40})?$\")') |
first }}"
message: git_commit must be empty or a commit sha of 7 to 40 lowercase hex
characters, for example 228aad84f1.
style: ERROR
behavior: BLOCK_EXECUTION
- when: "{{ {'d': inputs.project_dir} | jq('.d |
test(\"^(\\\\.|[A-Za-z0-9_-][A-Za-z0-9_./-]*)$\") and (contains(\"..\") |
not)') | first }}"
message: project_dir must be a relative path inside the repository such as `.`
or `dbt`, without `..` or a leading slash.
style: ERROR
behavior: BLOCK_EXECUTION
triggers:
- id: github_push
type: io.kestra.plugin.core.trigger.Webhook
description: |
Point a GitHub push webhook at `/api/v1/main/executions/webhook/company.team/dbt-slim-ci-with-manifest-promotion/<key>`
with content type `application/json`. `plan` reads `ref` and `after` from the payload: a push to `production_branch`
runs as main and promotes, any other branch runs as pr. The key comes from the `GITHUB_WEBHOOK_KEY` secret, never
from the flow source: a push to `production_branch` promotes a manifest, so whoever knows the key can promote.
key: "{{ secret('GITHUB_WEBHOOK_KEY') }}"
- id: nightly_promotion
type: io.kestra.plugin.core.trigger.Schedule
description: Rebuilds production and promotes its manifest every night, so slim
CI compares against a manifest produced by the current dbt version even
when nothing was merged. Shipped disabled.
disabled: true
cron: "0 2 * * *"
inputs:
mode: main
tasks:
- id: production_pointer
type: io.kestra.plugin.core.kv.Get
description: The pointer record written by the last promotion (git sha, dbt
version, time). Its absence is the signal that no production manifest
exists yet, and `errorOnMissing` false makes that a value rather than an
error.
key: "{{ inputs.manifest_key }}_meta"
errorOnMissing: false
- id: plan
type: io.kestra.plugin.core.output.OutputValues
description: |
Resolves what this run does, once, so every later task reads the same answer. A GitHub push payload (`trigger.body.ref`,
`trigger.body.after`) wins over the inputs. `slim` is true only for a pr run that has a production pointer; without one
the pr run is a full build and the final message says so. `selector` is empty for every full build.
values:
branch: "{{ (trigger.body.ref ?? '') != '' ? (trigger.body.ref |
replace({'refs/heads/': ''})) : (inputs.mode == 'main' ?
inputs.production_branch : inputs.git_ref) }}"
commit: "{{ (trigger.body.ref ?? '') != '' ? (trigger.body.after ?? '') :
inputs.git_commit }}"
mode: "{{ (trigger.body.ref ?? '') != '' ? ((trigger.body.ref |
replace({'refs/heads/': ''})) == inputs.production_branch ? 'main' :
'pr') : inputs.mode }}"
has_pointer: "{{ (outputs.production_pointer.value ?? '') != '' }}"
pointer: "{{ (outputs.production_pointer.value ?? {}) | toJson }}"
slim: "{{ ((trigger.body.ref ?? '') != '' ? ((trigger.body.ref |
replace({'refs/heads/': ''})) == inputs.production_branch ? 'main' :
'pr') : inputs.mode) == 'pr' and (outputs.production_pointer.value ??
'') != '' }}"
selector: "{{ (((trigger.body.ref ?? '') != '' ? ((trigger.body.ref |
replace({'refs/heads/': ''})) == inputs.production_branch ? 'main' :
'pr') : inputs.mode) == 'pr' and (outputs.production_pointer.value ??
'') != '') ? vars.slim_flags : '' }}"
dbt_target: "{{ inputs.dbt_target != '' ? inputs.dbt_target :
(((trigger.body.ref ?? '') != '' ? ((trigger.body.ref |
replace({'refs/heads/': ''})) == inputs.production_branch ? 'main' :
'pr') : inputs.mode) == 'main' ? 'prod' : 'ci') }}"
meta_key: "{{ inputs.manifest_key }}_meta"
run_url: "{{ kestra.url ?? inputs.kestra_api_url }}/ui/{{ vars.tenant
}}/executions/{{ flow.namespace }}/{{ flow.id }}/{{ execution.id }}"
- id: announce
type: io.kestra.plugin.core.log.Log
description: Says up front which of the three paths this run takes, so the
fallback is visible before dbt prints a word.
level: "{{ outputs.plan.values.mode == 'pr' and outputs.plan.values.has_pointer
== 'false' ? 'WARN' : 'INFO' }}"
message: >-
{% set p = outputs.plan.values %}{% set ref = p.commit != '' ? p.commit :
p.branch %}{{ p.mode == 'main'
? 'main run: full dbt build of ' ~ ref ~ ', manifest promoted to KV ' ~ inputs.manifest_key ~ ' only if every node succeeds.'
: (p.slim == 'true'
? 'pr run: slim CI of ' ~ ref ~ ' against the production manifest promoted from ' ~ (fromJson(p.pointer).git_sha ?? '?') ~ ' at ' ~ (fromJson(p.pointer).promoted_at ?? '?') ~ ' (dbt ' ~ (fromJson(p.pointer).dbt_version ?? '?') ~ '). Only state:modified+ nodes are built.'
: 'pr run: NO production manifest under KV ' ~ inputs.manifest_key ~ ' yet, falling back to a full build of ' ~ ref ~ '. Run this flow once with mode=main to promote one; slim CI starts with the next pr run.') }}
- id: dbt
type: io.kestra.plugin.core.flow.WorkingDirectory
description: Clone and build share one directory. Exactly one Clone task runs
(branch or pinned commit) and exactly one DbtCLI task runs (main or pr),
selected by `runIf`.
tasks:
- id: clone_branch
type: io.kestra.plugin.git.Clone
description: |
Shallow clone of the branch. `commit` and `branch` cannot both be set on one Clone task and an empty `commit` is
an error, hence two tasks. No `retry` on either: in Kestra 2.0.5 a retry on a task inside `WorkingDirectory`
re-created the WorkingDirectory task run and the execution never finished (observed with a missing branch).
A retry on the `dbt` WorkingDirectory would work but would also repeat a failed dbt build.
runIf: "{{ outputs.plan.values.commit == '' }}"
url: "{{ inputs.git_url }}"
branch: "{{ outputs.plan.values.branch }}"
- id: clone_commit
type: io.kestra.plugin.git.Clone
description: Detached checkout of a pinned sha. Not shallow, because the sha may
not be a branch head.
runIf: "{{ outputs.plan.values.commit != '' }}"
url: "{{ inputs.git_url }}"
commit: "{{ outputs.plan.values.commit }}"
- id: build_production
type: io.kestra.plugin.dbt.cli.DbtCLI
description: |
Full build of production. No `storeManifest` here on purpose: the plugin stores the manifest after the commands
finish whether or not dbt exited 0, so a failing test would still replace the promoted manifest. The plugin exposes
`target/manifest.json` as `outputFiles['manifest.json']` whenever the file exists; `promote_manifest` below reads it
and runs only after this task succeeded. `outputFiles` also keeps `run_results.json` and the git refs for the report,
and those survive a failed dbt command.
runIf: "{{ outputs.plan.values.mode == 'main' }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
containerImage: ghcr.io/kestra-io/dbt-duckdb:latest
projectDir: "{{ inputs.project_dir }}"
outputFiles:
- "{{ inputs.project_dir == '.' ? '' : inputs.project_dir ~ '/'
}}target/run_results.json"
- .git/HEAD
- .git/refs/heads/*
- .git/packed-refs
profiles: |
{{ inputs.dbt_profile }}:
target: {{ outputs.plan.values.dbt_target }}
outputs:
prod:
type: duckdb
path: "{{ inputs.duckdb_path }}"
schema: prod
threads: 4
ci:
type: duckdb
path: "{{ inputs.duckdb_path }}"
schema: ci
threads: 4
commands:
- dbt deps
- dbt build
- id: build_pull_request
type: io.kestra.plugin.dbt.cli.DbtCLI
description: |
`loadManifest` writes the promoted manifest to `target/manifest.json` before dbt starts. dbt rewrites that file while
parsing, before it reads `--state`, so comparing against `--state target` always finds zero changes (dbt warns
"state and target directories are the same"). The build therefore writes to `--target-path target_ci` and the
selector reads the untouched `target/`. No `storeManifest`: a pull request never promotes. `allowWarning` because
dbt logs a WARNING when the selector matches nothing (a pull request that changes no dbt node), which would end the
task, and the execution, in WARNING; test results with severity warn are still counted and reported.
runIf: "{{ outputs.plan.values.mode == 'pr' }}"
allowWarning: true
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
containerImage: ghcr.io/kestra-io/dbt-duckdb:latest
projectDir: "{{ inputs.project_dir }}"
loadManifest:
key: "{{ inputs.manifest_key }}"
namespace: "{{ flow.namespace }}"
outputFiles:
- "{{ inputs.project_dir == '.' ? '' : inputs.project_dir ~ '/' }}{{
vars.ci_target_path }}/run_results.json"
- .git/HEAD
- .git/refs/heads/*
- .git/packed-refs
profiles: |
{{ inputs.dbt_profile }}:
target: {{ outputs.plan.values.dbt_target }}
outputs:
prod:
type: duckdb
path: "{{ inputs.duckdb_path }}"
schema: prod
threads: 4
ci:
type: duckdb
path: "{{ inputs.duckdb_path }}"
schema: ci
threads: 4
commands:
- dbt deps
- dbt build {{ outputs.plan.values.selector }} --target-path {{
vars.ci_target_path }}
- id: artifacts
type: io.kestra.plugin.core.output.OutputValues
description: |
Which of the two DbtCLI tasks ran decides where `run_results.json` is. The skipped task has no outputs, so `??` falls
through to the other one. Files are picked by the end of their key, not the full path, because the key carries the
project directory as written and the worker's path separator (`.git/HEAD` on Linux, `.git\HEAD` on Windows).
values:
run_results: "{{ (outputs.build_production.outputFiles ??
outputs.build_pull_request.outputFiles) | jq('[to_entries[] |
select(.key | endswith(\"run_results.json\")) | .value][0]') | first }}"
head: "{{ (outputs.build_production.outputFiles ??
outputs.build_pull_request.outputFiles) | jq('[to_entries[] |
select(.key | endswith(\"HEAD\")) | .value][0]') | first }}"
branch_ref: "{{ (outputs.build_production.outputFiles ??
outputs.build_pull_request.outputFiles) | jq('[to_entries[] |
select(.key | contains(\"heads\")) | .value][0]') | first }}"
packed_refs: "{{ (outputs.build_production.outputFiles ??
outputs.build_pull_request.outputFiles) | jq('[to_entries[] |
select(.key | endswith(\"packed-refs\")) | .value][0]') | first }}"
manifest: "{{ (outputs.build_production.outputFiles ??
outputs.build_pull_request.outputFiles) | jq('[to_entries[] |
select(.key | endswith(\"manifest.json\")) | .value][0]') | first }}"
- id: results
type: io.kestra.plugin.core.output.OutputValues
description: |
`run_results.json` is read with `read()` and shaped with `jq`: counts per status, every node that ran as `type:name`,
the failing ones, and dbt's own version from `metadata`. The git sha comes from `.git/HEAD`, following the ref to the
loose ref file or `packed-refs`, because Clone exposes no sha output.
values:
dbt_version: "{{
(fromJson(read(outputs.artifacts.values.run_results))).metadata.dbt_ver\
sion }}"
counts: "{{ fromJson(read(outputs.artifacts.values.run_results)) | jq('{total:
(.results | length), success: ([.results[] | select(.status ==
\"success\" or .status == \"pass\")] | length), warn: ([.results[] |
select(.status == \"warn\")] | length), failed: ([.results[] |
select(.status == \"error\" or .status == \"fail\" or .status ==
\"runtime error\")] | length), skipped: ([.results[] | select(.status ==
\"skipped\")] | length)}') | first | toJson }}"
nodes: "{{ fromJson(read(outputs.artifacts.values.run_results)) |
jq('[.results[] | (.unique_id | split(\".\") | .[0] + \":\" + .[2])]') |
first | toJson }}"
failing: "{{ fromJson(read(outputs.artifacts.values.run_results)) |
jq('[.results[] | select(.status == \"error\" or .status == \"fail\" or
.status == \"runtime error\") | (.unique_id | split(\".\") | .[0] +
\":\" + .[2]) + \" (\" + .status + \")\"]') | first | toJson }}"
git_sha: >-
{% set a = outputs.artifacts.values %}{% set head = read(a.head) | trim
%}{% set ref = head | split(' ') | last %}{{ ref == head ? head :
((a.branch_ref ?? '') != '' ? (read(a.branch_ref) | trim) : ({'p':
read(a.packed_refs)} | jq('.p | capture("(?<sha>[0-9a-f]{40}) " + "' ~
ref ~ '").sha') | first)) }}
- id: promote_manifest
type: io.kestra.plugin.core.kv.Set
description: |
The promotion itself, reached only when `build_production` succeeded, which is what "green" means here: the task
fails on any non-zero dbt exit, a failing test included. The manifest the build wrote is stored as JSON under
`manifest_key`, the same shape the plugin's `loadManifest` reads back in pr runs.
runIf: "{{ outputs.plan.values.mode == 'main' }}"
key: "{{ inputs.manifest_key }}"
kvType: JSON
value: "{{ read(outputs.artifacts.values.manifest) }}"
- id: promote
type: io.kestra.plugin.core.kv.Set
description: |
The pointer record, written after the manifest and only in main mode. It is what pr runs read to decide between
slim CI and the fallback, and it carries the dbt version the manifest was produced with. If this write failed after
the manifest one, the next pr run would fall back to a full build, which is the safe direction.
runIf: "{{ outputs.plan.values.mode == 'main' }}"
key: "{{ outputs.plan.values.meta_key }}"
kvType: JSON
value: "{{ {'git_sha': outputs.results.values.git_sha, 'git_ref':
outputs.plan.values.commit != '' ? outputs.plan.values.commit :
outputs.plan.values.branch, 'promoted_at': execution.startDate,
'dbt_version': outputs.results.values.dbt_version, 'nodes':
fromJson(outputs.results.values.counts).total, 'execution_id':
execution.id, 'manifest_key': inputs.manifest_key} | toJson }}"
- id: confirm_promotion
type: io.kestra.plugin.core.kv.Get
description: Reads the pointer back. The summary and the flow output say
`promoted` only when the record in KV names this execution, not merely
because the Set task was reached.
runIf: "{{ outputs.plan.values.mode == 'main' }}"
key: "{{ outputs.plan.values.meta_key }}"
- id: version_drift
type: io.kestra.plugin.core.log.Log
description: |
Slim CI compares manifests, and manifests written by different dbt versions, or by env-dependent configs, differ in
places that have nothing to do with the pull request, which shows up as spurious modified nodes. The pointer carries
the production dbt version; a pr run on another version is warned, not failed.
runIf: "{{ outputs.plan.values.slim == 'true' and
(fromJson(outputs.plan.values.pointer).dbt_version ?? '') !=
outputs.results.values.dbt_version }}"
level: WARN
message: "dbt version drift: the production manifest was produced by dbt {{
fromJson(outputs.plan.values.pointer).dbt_version ?? '?' }}, this run uses
dbt {{ outputs.results.values.dbt_version }}. state:modified+ may have
selected nodes the pull request did not touch. Re-run a main promotion on
the new version to realign."
- id: report
type: io.kestra.plugin.core.output.OutputValues
description: One message for the log and Slack. It names the path taken, the ref
and sha, the counts, and every node that ran when the list is short; the
zero-node case says so instead of printing an empty list.
values:
message: >-
{% set p = outputs.plan.values %}{% set r = outputs.results.values %}{%
set c = fromJson(r.counts) %}{% set nodes = fromJson(r.nodes) %}{% set
ref = p.commit != '' ? p.commit : p.branch %}{{ p.mode == 'main'
? 'dbt production build of ' ~ ref ~ '@' ~ (r.git_sha | slice(0, 10)) ~ ' succeeded: ' ~ c.total ~ ' nodes (' ~ c.success ~ ' success, ' ~ c.warn ~ ' warn, ' ~ c.skipped ~ ' skipped). Manifest promoted to KV ' ~ inputs.manifest_key ~ ' with dbt ' ~ r.dbt_version ~ '.'
: (p.slim == 'true'
? (c.total == 0
? 'dbt slim CI of ' ~ ref ~ '@' ~ (r.git_sha | slice(0, 10)) ~ ': 0 nodes modified relative to production ' ~ ((fromJson(p.pointer).git_sha ?? '??????????') | slice(0, 10)) ~ ', nothing was built or tested. Not a failure: the pull request changes no dbt node.'
: 'dbt slim CI of ' ~ ref ~ '@' ~ (r.git_sha | slice(0, 10)) ~ ' against production ' ~ ((fromJson(p.pointer).git_sha ?? '??????????') | slice(0, 10)) ~ ': ' ~ c.total ~ ' modified+ nodes built (' ~ c.success ~ ' success, ' ~ c.warn ~ ' warn, ' ~ c.skipped ~ ' skipped): ' ~ ((nodes | length) > 40 ? ((nodes | slice(0, 40)) | join(', ')) ~ ' and ' ~ ((nodes | length) - 40) ~ ' more' : (nodes | join(', '))) ~ '.')
: 'dbt FULL build of ' ~ ref ~ '@' ~ (r.git_sha | slice(0, 10)) ~ ' (fallback, no production manifest under KV ' ~ inputs.manifest_key ~ '): ' ~ c.total ~ ' nodes (' ~ c.success ~ ' success, ' ~ c.warn ~ ' warn, ' ~ c.skipped ~ ' skipped). Nothing promoted; run mode=main once to enable slim CI.') }}
- id: log_report
type: io.kestra.plugin.core.log.Log
description: The same message Slack gets, in the execution log, so the outcome
is readable without opening Slack.
message: "{{ outputs.report.values.message }} {{ outputs.plan.values.run_url }}"
- id: notify
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Reads the webhook from the `SLACK_WEBHOOK_URL` secret;
`allowFailure` so a Slack outage does not fail a green build that already
promoted.
allowFailure: true
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: ":white_check_mark: {{ outputs.report.values.message }} {{
outputs.plan.values.run_url }}"
retry:
type: constant
maxAttempts: 3
interval: PT15S
errors:
- id: failure_context
type: io.kestra.plugin.core.output.OutputValues
description: |
`errorLogs()` names the task that failed. When dbt itself failed, `outputFiles` of the failed task are still there, so
`run_results.json` is read for the nodes with status error or fail, which is what the message leads with. A failed
Clone or a blocked check leaves no run results and the message says which task failed instead.
values:
failed_task: "{{ ((errorLogs() | length) > 0 and (errorLogs()[0].taskId ?? '')
!= '') ? errorLogs()[0].taskId : 'none' }}"
failure_message: "{{ (errorLogs() | length) > 0 ? errorLogs()[0].message : 'no
task error was logged' }}"
run_results: "{{ (outputs.build_production.outputFiles ??
outputs.build_pull_request.outputFiles ?? {}) | jq('[to_entries[] |
select(.key | endswith(\"run_results.json\")) | .value][0] // \"\"') |
first }}"
- id: failing_nodes
type: io.kestra.plugin.core.output.OutputValues
description: Failing nodes as `type:name (status)` and the per-status counts
from the failed build's `run_results.json`; empty when the failure
happened before dbt ran.
values:
failing: "{{ outputs.failure_context.values.run_results != '' ?
(fromJson(read(outputs.failure_context.values.run_results)) |
jq('[.results[] | select(.status == \"error\" or .status == \"fail\" or
.status == \"runtime error\") | (.unique_id | split(\".\") | .[0] +
\":\" + .[2]) + \" (\" + .status + \")\"]') | first | toJson) : '[]' }}"
counts: "{{ outputs.failure_context.values.run_results != '' ?
(fromJson(read(outputs.failure_context.values.run_results)) |
jq('{total: (.results | length), success: ([.results[] | select(.status
== \"success\" or .status == \"pass\")] | length), failed: ([.results[]
| select(.status == \"error\" or .status == \"fail\" or .status ==
\"runtime error\")] | length), skipped: ([.results[] | select(.status ==
\"skipped\")] | length)}') | first | toJson) : '{}' }}"
- id: failure_report
type: io.kestra.plugin.core.output.OutputValues
description: Leads with the failing dbt nodes when there are any, otherwise with
the failed task and its first error line. A main run also says that
nothing was promoted.
values:
message: >-
{% set f = fromJson(outputs.failing_nodes.values.failing) %}{% set p =
outputs.plan.values ?? {} %}{{ 'dbt ' ~ (p.mode ?? inputs.mode) ~ ' run
of ' ~ ((p.commit ?? inputs.git_commit) != '' ? (p.commit ??
inputs.git_commit) : (p.branch ?? inputs.git_ref)) ~ ' FAILED in task '
~ outputs.failure_context.values.failed_task ~ ((f | length) > 0 ? ': '
~ (f | length) ~ ' dbt node(s) failed: ' ~ (f | join(', ')) : ': ' ~
outputs.failure_context.values.failure_message) ~ ((p.mode ??
inputs.mode) == 'main' ? '. Nothing was promoted; KV ' ~
inputs.manifest_key ~ ' still holds the previous manifest.' : '.') }}
- id: log_failure
type: io.kestra.plugin.core.log.Log
description: ERROR line with the failure message and the execution link, written
before the KV and Slack steps so it is there even if those fail.
level: ERROR
message: "{{ outputs.failure_report.values.message }} {{
outputs.plan.values.run_url ?? execution.id }}"
- id: remember_failure
type: io.kestra.plugin.core.kv.Set
description: Last failure next to the manifest, 30 days, for whoever looks at
the pointer and wonders why the latest run did not promote.
key: "{{ inputs.manifest_key }}_last_failure"
kvType: JSON
ttl: P30D
value: "{{ {'execution_id': execution.id, 'failed_at': execution.startDate,
'mode': outputs.plan.values.mode ?? inputs.mode, 'ref':
outputs.plan.values.branch ?? inputs.git_ref, 'commit':
outputs.plan.values.commit ?? inputs.git_commit, 'task':
outputs.failure_context.values.failed_task, 'failing_nodes':
fromJson(outputs.failing_nodes.values.failing), 'message':
outputs.failure_context.values.failure_message} | toJson }}"
- id: alert_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Same `SLACK_WEBHOOK_URL` secret; allowFailure so a Slack problem
does not hide the dbt error; the same text is in the ERROR log above.
allowFailure: true
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: ":rotating_light: {{ outputs.failure_report.values.message }} {{
outputs.plan.values.run_url ?? execution.id }}"
retry:
type: constant
maxAttempts: 3
interval: PT15S
finally:
- id: summary
type: io.kestra.plugin.core.log.Log
description: One line per run whatever happened, `n/a` for the steps that did not run.
message: "mode={{ outputs.plan.values.mode ?? inputs.mode }} ref={{
outputs.plan.values.branch ?? inputs.git_ref }} commit={{
outputs.plan.values.commit ?? inputs.git_commit }} slim={{
outputs.plan.values.slim ?? 'n/a' }} sha={{ outputs.results.values.git_sha
?? 'n/a' }} dbt={{ outputs.results.values.dbt_version ?? 'n/a' }}
counts={{ outputs.results.values.counts ??
outputs.failing_nodes.values.counts ?? 'n/a' }} promoted={{
(outputs.confirm_promotion.value.execution_id ?? '') == execution.id ?
'yes' : 'no' }}"
outputs:
- id: summary
type: JSON
value: "{{ {'mode': outputs.plan.values.mode ?? inputs.mode, 'ref':
outputs.plan.values.branch ?? inputs.git_ref, 'commit':
outputs.plan.values.commit ?? inputs.git_commit, 'slim':
outputs.plan.values.slim ?? null, 'git_sha':
outputs.results.values.git_sha ?? null, 'dbt_version':
outputs.results.values.dbt_version ?? null, 'counts':
fromJson(outputs.results.values.counts ??
outputs.failing_nodes.values.counts ?? '{}'), 'nodes':
fromJson(outputs.results.values.nodes ?? '[]'), 'failing':
fromJson(outputs.results.values.failing ??
outputs.failing_nodes.values.failing ?? '[]'), 'promoted':
(outputs.confirm_promotion.value.execution_id ?? '') == execution.id} |
toJson }}"