removed slack task and added bash script instead. Updated gitlab-ci config file

This commit is contained in:
James Lopez 2016-02-05 11:04:13 +01:00
parent 70f82cc5ac
commit 0309e0818a
3 changed files with 20 additions and 13 deletions

View File

@ -183,8 +183,11 @@ spinach:ruby21:
notify:slack:
stage: notifications
script:
- bundle exec rake ci:slack:error["#ci-test","Build failed for master/tags"]
- source ./scripts/notify_slack.sh "#ci-test" "Build failed for master/tags!"
when: on_failure
only:
- master
- tags
# TODO: uncomment these lines.
#only:
# - master@gitlab-org/gitlab-ce
# - tags@gitlab-org/gitlab-ce
# - master@gitlab-org/gitlab-ee
# - tags@gitlab-org/gitlab-ee

View File

@ -1,9 +0,0 @@
namespace :ci do
namespace :slack do
desc "GitLab CI | Send slack notification on build failure"
task :error, [:channel, :error] do |t, args|
next unless !"#{ENV['CI_SLACK_WEBHOOK_URL']}".blank? && args.channel && args.error
Kernel.system "curl -X POST --data-urlencode 'payload={\"channel\": \"#{args.channel}\", \"username\": \"gitlab-ci\", \"text\": \"#{args.error}\", \"icon_emoji\": \":gitlab:\"}' $CI_SLACK_WEBHOOK_URL"
end
end
end

13
scripts/notify_slack.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
# Sends Slack notification ERROR_MSG to CHANNEL
# An env. variable CI_SLACK_WEBHOOK_URL needs to be set.
CHANNEL=$1
ERROR_MSG=$2
if [ -z "$CHANNEL" ] || [ -z "$ERROR_MSG" ] || [ -z "$CI_SLACK_WEBHOOK_URL" ]; then
echo "Missing argument(s) - Use: $0 channel message"
echo "and set CI_SLACK_WEBHOOK_URL environment variable."
else
curl -X POST --data-urlencode 'payload={"channel": "'"$CHANNEL"'", "username": "gitlab-ci", "text": "'"$ERROR_MSG"'", "icon_emoji": ":gitlab:"}' "$CI_SLACK_WEBHOOK_URL"
fi