diff --git a/ankh/main.go b/ankh/main.go index 88f1b911..2b766edc 100644 --- a/ankh/main.go +++ b/ankh/main.go @@ -431,8 +431,12 @@ func execute(ctx *ankh.ExecutionContext) { executeContext(ctx, &rootAnkhFile) } - if ctx.SlackChannel != "" { - if err := slack.PingSlackChannel(ctx); err != nil { + if len(ctx.SlackChannels) > 0 { + if ctx.Mode == ankh.Rollback { + ctx.SlackDeploymentVersion = "rollback" + } + err := slack.PingSlackChannel(ctx) + if err != nil { ctx.Logger.Errorf("Slack message failed with error: %v", err) } } @@ -908,7 +912,7 @@ func main() { ctx.LocalChart = true } ctx.Mode = ankh.Apply - ctx.SlackChannel = *slackChannel + ctx.SlackChannels = append(ctx.SlackChannels, *slackChannel) ctx.SlackMessageOverride = *slackMessageOverride ctx.CreateJiraTicket = *createJiraTicket filters := []string{} @@ -942,7 +946,7 @@ func main() { ctx.LocalChart = true } ctx.Mode = ankh.Rollback - ctx.SlackChannel = *slackChannel + ctx.SlackChannels = append(ctx.SlackChannels, *slackChannel) ctx.SlackMessageOverride = *slackMessageOverride ctx.CreateJiraTicket = *createJiraTicket ctx.Filters = []string{"deployment", "statfulset"} diff --git a/context/context.go b/context/context.go index 8e148114..ef113e2c 100644 --- a/context/context.go +++ b/context/context.go @@ -55,10 +55,11 @@ type ExecutionContext struct { DeploymentTag string - SlackChannel string SlackMessageOverride string - CreateJiraTicket bool + CreateJiraTicket bool + SlackChannels []string + SlackDeploymentVersion string Filters []string @@ -201,7 +202,7 @@ func (ctx *ExecutionContext) DetermineHelmRepository(preferredRepository *string return repository } - ctx.Logger.Fatalf("No helm repository configured. "+ + ctx.Logger.Fatalf("No helm repository configured. " + "Set `helm.repository` globally, pass it as an argument, or see README.md") return "" } diff --git a/slack/slack.go b/slack/slack.go index 85f5763a..8510d62b 100644 --- a/slack/slack.go +++ b/slack/slack.go @@ -52,16 +52,22 @@ func PingSlackChannel(ctx *ankh.ExecutionContext) error { Username: username, } - channelId, err := getSlackChannelIDByName(api, ctx.SlackChannel) - if err != nil { - return err - } - - if !ctx.DryRun { - _, _, err = api.PostMessage(channelId, slack.MsgOptionAttachments(attachment), slack.MsgOptionPostMessageParameters(messageParams)) - } else { - ctx.Logger.Infof("--dry-run set so not sending message '%v' to slack channel %v", messageText, ctx.SlackChannel) - } + channels := make(map[string]string, len(ctx.SlackChannels)) + for _, ch := range ctx.SlackChannels { + channelId, err := getSlackChannelIDByName(api, ch) + if err != nil { + return err + } + channels[ch] = channelId + } + + for name, id := range channels { + if !ctx.DryRun { + _, _, err = api.PostMessage(id, slack.MsgOptionAttachments(attachment), slack.MsgOptionPostMessageParameters(messageParams)) + } else { + ctx.Logger.Infof("--dry-run set so not sending message '%v' to slack channel %v", messageText, name) + } + } return err }