Skip to content
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

allow a different webhook to be used to send messages on build failures #76

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 15 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ type Config struct {
Debug bool `env:"is_debug_mode,opt[yes,no]"`

// Message
WebhookURL stepconf.Secret `env:"webhook_url"`
APIToken stepconf.Secret `env:"api_token"`
Channel string `env:"channel"`
ChannelOnError string `env:"channel_on_error"`
Text string `env:"text"`
TextOnError string `env:"text_on_error"`
IconEmoji string `env:"emoji"`
IconEmojiOnError string `env:"emoji_on_error"`
IconURL string `env:"icon_url"`
IconURLOnError string `env:"icon_url_on_error"`
LinkNames bool `env:"link_names,opt[yes,no]"`
Username string `env:"from_username"`
UsernameOnError string `env:"from_username_on_error"`
WebhookURL stepconf.Secret `env:"webhook_url"`
WebhookURLOnError stepconf.Secret `env:"webhook_url_on_error"`
APIToken stepconf.Secret `env:"api_token"`
Channel string `env:"channel"`
ChannelOnError string `env:"channel_on_error"`
Text string `env:"text"`
TextOnError string `env:"text_on_error"`
IconEmoji string `env:"emoji"`
IconEmojiOnError string `env:"emoji_on_error"`
IconURL string `env:"icon_url"`
IconURLOnError string `env:"icon_url_on_error"`
LinkNames bool `env:"link_names,opt[yes,no]"`
Username string `env:"from_username"`
UsernameOnError string `env:"from_username_on_error"`

// Attachment
Color string `env:"color,required"`
Expand Down Expand Up @@ -109,7 +110,7 @@ func postMessage(conf Config, msg Message) error {
}
log.Debugf("Request to Slack: %s\n", b)

url := strings.TrimSpace(string(conf.WebhookURL))
url := strings.TrimSpace(selectValue(string(conf.WebhookURL), string(conf.WebhookURLOnError)))
if url == "" {
url = "https://slack.com/api/chat.postMessage"
}
Expand Down
9 changes: 9 additions & 0 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ inputs:
To register an **Incoming WebHook integration** visit: https://api.slack.com/incoming-webhooks
is_required: false
is_sensitive: true
- webhook_url_on_error:
opts:
title: "Slack Webhook URL (Webhook or API token is required) if the build failed"
description: |
**Either webhook\_url or api\_token input is required.**
To register an **Incoming WebHook integration** visit: https://api.slack.com/incoming-webhooks
is_required: false
is_sensitive: true
category: If Build Failed
- api_token:
opts:
title: "Slack API token (Webhook or API token is required)"
Expand Down