diff options
-rw-r--r-- | .gitlab-ci.yml | 11 | ||||
-rw-r--r-- | lib/tasks/ci/slack.rake | 9 | ||||
-rwxr-xr-x | scripts/notify_slack.sh | 13 |
3 files changed, 20 insertions, 13 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 997994485da..290fa120812 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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
\ No newline at end of file + # 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
\ No newline at end of file diff --git a/lib/tasks/ci/slack.rake b/lib/tasks/ci/slack.rake deleted file mode 100644 index 0afc0e908d1..00000000000 --- a/lib/tasks/ci/slack.rake +++ /dev/null @@ -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 diff --git a/scripts/notify_slack.sh b/scripts/notify_slack.sh new file mode 100755 index 00000000000..0a4239e132c --- /dev/null +++ b/scripts/notify_slack.sh @@ -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
\ No newline at end of file |