BigW Consortium Gitlab

Commit 0309e081 by James Lopez

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

parent 70f82cc5
...@@ -183,8 +183,11 @@ spinach:ruby21: ...@@ -183,8 +183,11 @@ spinach:ruby21:
notify:slack: notify:slack:
stage: notifications stage: notifications
script: 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 when: on_failure
only: # TODO: uncomment these lines.
- master #only:
- tags # - master@gitlab-org/gitlab-ce
\ No newline at end of file # - tags@gitlab-org/gitlab-ce
# - master@gitlab-org/gitlab-ee
# - tags@gitlab-org/gitlab-ee
\ No newline at end of file
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
#!/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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment