lib/slamboo/slamboo.rb
def message_fail
            slackMsg = JSON.parse("{}")
            ci = JSON.parse("{}")

            options[:user] != nil ? slackMsg["username"] = options[:user] : nil
            options[:channel] != nil ? slackMsg["channel"] = "\##{options[:channel]}" : nil
            options[:userEmoji] != nil ? slackMsg["icon_emoji"] = options[:userEmoji] : nil

            options[:ciURL] != nil ? ci["ciURL"] = options[:ciURL] : nil
            options[:planName] != nil ? ci["planName"] = options[:planName] : nil
            options[:buildNumber] != nil ? ci["buildNumber"] = options[:buildNumber] : nil
            options[:triggerHash] != nil ? ci["triggerHash"] = options[:triggerHash] : nil
            options[:triggerUser] != nil ? ci["triggerUser"] = options[:triggerUser] : nil
            options[:pipelineGroup] != nil ? ci["pipelineGroup"] = options[:pipelineGroup] : nil


            resultColor = "#E02D19"

            slackMsg["attachments"] = []
            slackMsg["attachments"][0] = JSON.parse("{}")
            slackMsg["attachments"][0]["fallback"] ="Failed &gt; #{ci["pipelineGroup"]} &gt; #{ci["planName"]} | by #{ci["triggerUser"]}, hash \##{ci["triggerHash"]}"
            slackMsg["attachments"][0]["title"] = "#{ci["pipelineGroup"]} &gt; #{ci["planName"]}"
            slackMsg["attachments"][0]["title_link"] = "#{ci["ciURL"]}/go/pipelines/value_stream_map/#{ci["planName"]}/#{ci["buildNumber"]}"

            slackMsg["attachments"][0]["fields"] = []
            slackMsg["attachments"][0]["fields"][0] = JSON.parse("{}")
            slackMsg["attachments"][0]["fields"][0]["title"] = "Failed"
            slackMsg["attachments"][0]["fields"][0]["value"] = "Build number: #{ci["buildNumber"]}"
            slackMsg["attachments"][0]["fields"][0]["short"] = true
            slackMsg["attachments"][0]["fields"][1] = JSON.parse("{}")
            slackMsg["attachments"][0]["fields"][1]["title"] = "Reason:"
            slackMsg["attachments"][0]["fields"][1]["value"] = "by: #{ci["triggerUser"]}, hash: #{ci["triggerHash"]}"
            slackMsg["attachments"][0]["fields"][1]["short"] = true
            slackMsg["attachments"][0]["color"] = resultColor
            puts ">>>>>>>>>>>>>>>>>>>>>>"
            puts slackMsg
            puts ">>>>>>>>>>>>>>>>>>>>>>"

            slackURL=options[:sURL]
            uriStringSlack = slackURL
            uriSlack = URI(uriStringSlack)

            s = Resources::Request.new(uriSlack, nil, nil)
            sreq = s.create_post_request_header(JSON.generate(slackMsg))

            sres = Net::HTTP.start(uriSlack.hostname, 
                :use_ssl => uriSlack.scheme == 'https') { |http|
                http.request(sreq)
            }
            if sres.code != "200"
                puts sres.code
            else
                puts sres
            end
        end
# posts a message to Slack
# options
posts a message to Slack
options
posts a message to Slack options
def message_fail
            slackMsg = JSON.parse("{}")
            ci = JSON.parse("{}")
            options[:user] != nil ? slackMsg["username"] = options[:user] : nil
            options[:channel] != nil ? slackMsg["channel"] = "\##{options[:channel]}" : nil
            options[:userEmoji] != nil ? slackMsg["icon_emoji"] = options[:userEmoji] : nil
            options[:ciURL] != nil ? ci["ciURL"] = options[:ciURL] : nil
            options[:planName] != nil ? ci["planName"] = options[:planName] : nil
            options[:buildNumber] != nil ? ci["buildNumber"] = options[:buildNumber] : nil
            options[:triggerHash] != nil ? ci["triggerHash"] = options[:triggerHash] : nil
            options[:triggerUser] != nil ? ci["triggerUser"] = options[:triggerUser] : nil
            options[:pipelineGroup] != nil ? ci["pipelineGroup"] = options[:pipelineGroup] : nil
            resultColor = "#E02D19"
            slackMsg["attachments"] = []
            slackMsg["attachments"][0] = JSON.parse("{}")
            slackMsg["attachments"][0]["fallback"] ="Failed &gt; #{ci["pipelineGroup"]} &gt; #{ci["planName"]} | by #{ci["triggerUser"]}, hash \##{ci["triggerHash"]}"
            slackMsg["attachments"][0]["title"] = "#{ci["pipelineGroup"]} &gt; #{ci["planName"]}"
            slackMsg["attachments"][0]["title_link"] = "#{ci["ciURL"]}/go/pipelines/value_stream_map/#{ci["planName"]}/#{ci["buildNumber"]}"
            slackMsg["attachments"][0]["fields"] = []
            slackMsg["attachments"][0]["fields"][0] = JSON.parse("{}")
            slackMsg["attachments"][0]["fields"][0]["title"] = "Failed"
            slackMsg["attachments"][0]["fields"][0]["value"] = "Build number: #{ci["buildNumber"]}"
            slackMsg["attachments"][0]["fields"][0]["short"] = true
            slackMsg["attachments"][0]["fields"][1] = JSON.parse("{}")
            slackMsg["attachments"][0]["fields"][1]["title"] = "Reason:"
            slackMsg["attachments"][0]["fields"][1]["value"] = "by: #{ci["triggerUser"]}, hash: #{ci["triggerHash"]}"
            slackMsg["attachments"][0]["fields"][1]["short"] = true
            slackMsg["attachments"][0]["color"] = resultColor
            puts ">>>>>>>>>>>>>>>>>>>>>>"
            puts slackMsg
            puts ">>>>>>>>>>>>>>>>>>>>>>"
            slackURL=options[:sURL]
            uriStringSlack = slackURL
            uriSlack = URI(uriStringSlack)
            s = Resources::Request.new(uriSlack, nil, nil)
            sreq = s.create_post_request_header(JSON.generate(slackMsg))
            sres = Net::HTTP.start(uriSlack.hostname, 
                :use_ssl => uriSlack.scheme == 'https') { |http|
                http.request(sreq)
            }
            if sres.code != "200"
                puts sres.code
            else
                puts sres
            end
        end
def message_fail slackMsg = JSON . parse ( "{}" ) ci = JSON . parse ( "{}" ) options [ :user ] != nil ? slackMsg [ "username" ] = options [ :user ] : nil options [ :channel ] != nil ? slackMsg [ "channel" ] = "\##{options[:channel]}" : nil options [ :userEmoji ] != nil ? slackMsg [ "icon_emoji" ] = options [ :userEmoji ] : nil options [ :ciURL ] != nil ? ci [ "ciURL" ] = options [ :ciURL ] : nil options [ :planName ] != nil ? ci [ "planName" ] = options [ :planName ] : nil options [ :buildNumber ] != nil ? ci [ "buildNumber" ] = options [ :buildNumber ] : nil options [ :triggerHash ] != nil ? ci [ "triggerHash" ] = options [ :triggerHash ] : nil options [ :triggerUser ] != nil ? ci [ "triggerUser" ] = options [ :triggerUser ] : nil options [ :pipelineGroup ] != nil ? ci [ "pipelineGroup" ] = options [ :pipelineGroup ] : nil resultColor = "#E02D19" slackMsg [ "attachments" ] = [ ] slackMsg [ "attachments" ] [ 0 ] = JSON . parse ( "{}" ) slackMsg [ "attachments" ] [ 0 ] [ "fallback" ] = "Failed &gt; #{ci["pipelineGroup"]} &gt; #{ci["planName"]} | by #{ci["triggerUser"]}, hash \##{ci["triggerHash"]}" slackMsg [ "attachments" ] [ 0 ] [ "title" ] = "#{ci["pipelineGroup"]} &gt; #{ci["planName"]}" slackMsg [ "attachments" ] [ 0 ] [ "title_link" ] = "#{ci["ciURL"]}/go/pipelines/value_stream_map/#{ci["planName"]}/#{ci["buildNumber"]}" slackMsg [ "attachments" ] [ 0 ] [ "fields" ] = [ ] slackMsg [ "attachments" ] [ 0 ] [ "fields" ] [ 0 ] = JSON . parse ( "{}" ) slackMsg [ "attachments" ] [ 0 ] [ "fields" ] [ 0 ] [ "title" ] = "Failed" slackMsg [ "attachments" ] [ 0 ] [ "fields" ] [ 0 ] [ "value" ] = "Build number: #{ci["buildNumber"]}" slackMsg [ "attachments" ] [ 0 ] [ "fields" ] [ 0 ] [ "short" ] = true slackMsg [ "attachments" ] [ 0 ] [ "fields" ] [ 1 ] = JSON . parse ( "{}" ) slackMsg [ "attachments" ] [ 0 ] [ "fields" ] [ 1 ] [ "title" ] = "Reason:" slackMsg [ "attachments" ] [ 0 ] [ "fields" ] [ 1 ] [ "value" ] = "by: #{ci["triggerUser"]}, hash: #{ci["triggerHash"]}" slackMsg [ "attachments" ] [ 0 ] [ "fields" ] [ 1 ] [ "short" ] = true slackMsg [ "attachments" ] [ 0 ] [ "color" ] = resultColor puts ">>>>>>>>>>>>>>>>>>>>>>" puts slackMsg puts ">>>>>>>>>>>>>>>>>>>>>>" slackURL = options [ :sURL ] uriStringSlack = slackURL uriSlack = URI ( uriStringSlack ) s = Resources :: Request . new ( uriSlack , nil , nil ) sreq = s . create_post_request_header ( JSON . generate ( slackMsg ) ) sres = Net :: HTTP . start ( uriSlack . hostname , :use_ssl => uriSlack . scheme == 'https' ) { | http | http . request ( sreq ) } if sres . code != "200" puts sres . code else puts sres end end
posts a message to Slack
options
posts a message to Slack options