From 0d4adfedabf8424d0eb2b15fa29f15cd9d6f8fed Mon Sep 17 00:00:00 2001 From: dudicoco <51051860+dudicoco@users.noreply.github.com> Date: Tue, 8 Jun 2021 04:59:21 +0300 Subject: [PATCH] Document hooks events expressions (#1870) Docs for https://github.com/roboll/helmfile/pull/882 Ref https://github.com/roboll/helmfile/issues/1868#issuecomment-854530386 --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index 4a06daad..abdcd2f1 100644 --- a/README.md +++ b/README.md @@ -1143,6 +1143,40 @@ Now, replace `echo` with any command you like, and rewrite `args` that actually - linting - testing +Hooks expose additional template expressions: + +`.Event.Name` is the name of the hook event. + +`.Event.Error` is the error generated by a failed release, exposed for `posysync` hooks only when a release fails, otherwise its value is `nil`. + +You can use the hooks event expressions to send notifications to platforms such as `Slack`, `MS Teams`, etc. + +The following example passes arguments to a script which sends a notification: + +```yaml +releases: +- name: myapp + chart: mychart + # *snip* + hooks: + - events: + - presync + - postsync + showlogs: true + command: notify.sh + args: + - --event + - '{{`{{ .Event.Name }}`}}' + - --status + - '{{`{{ if .Event.Error }}failure{{ else }}success{{ end }}`}}' + - --environment + - '{{`{{ .Environment.Name }}`}}' + - --namespace + - '{{`{{ .Release.Namespace }}`}}' + - --release + - '{{`{{ .Release.Name }}`}}' +``` + For templating, imagine that you created a hook that generates a helm chart on-the-fly by running an external tool like ksonnet, kustomize, or your own template engine. It will allow you to write your helm releases with any language you like, while still leveraging goodies provided by helm.