Cake AddIn that extends Cake with Slack messaging features
Clone or download
devlead Merge branch 'release/0.12.0'
* release/0.12.0:
  Fix build script for release
Latest commit 3b26629 Jul 3, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
nuspec/nuget
src
tools
.gitattributes
.gitignore
LICENSE
README.md
ReleaseNotes.md
appveyor.yml
build.cake
build.ps1
samplemessage.png
samplemessageattachment.png
setup.cake

README.md

Cake.Slack

Cake AddIn that extends Cake with Slack messaging features Build status

Usage

Post message

Using token

#addin "Cake.Slack"
var slackToken = EnvironmentVariable("SLACK_TOKEN");
var slackChannel = "#cake";
var postMessageResult = Slack.Chat.PostMessage(
            token:slackToken,
            channel:slackChannel,
            text:"This _is_ a `message` from *CakeBuild* :thumbsup:\r\n```Here is some code```"
    );

if (postMessageResult.Ok)
{
    Information("Message {0} successfully sent", postMessageResult.TimeStamp);
}
else
{
    Error("Failed to send message: {0}", postMessageResult.Error);
}

Cake output will be similar to below:

Message 1420896696.000057 successfully sent

This will result in an message in your Slack channel similar to below:

Sample message

Using incoming web hook url

#addin "Cake.Slack"
var slackhookuri = EnvironmentVariable("slackhookuri");
var slackChannel = "#cake";
var postMessageResult = Slack.Chat.PostMessage(
            channel:slackChannel,
            text:"This _is_ a `message` from *CakeBuild* :thumbsup:\r\n```Here is some code```",
            messageSettings:new SlackChatMessageSettings { IncomingWebHookUrl = slackhookuri }
    );

if (postMessageResult.Ok)
{
    Information("Message successfully sent");
}
else
{
    Error("Failed to send message: {0}", postMessageResult.Error);
}

Cake output will be similar to below:

Message successfully sent

This will result in an message in your Slack channel similar to below:

Sample message

Using message attachments

#addin "Cake.Slack"
var slackWebHookUrl = EnvironmentVariable("slackWebHookUrl");
var slackChannel = "#cake";
var slackAssemblyFieldAttachment = new SlackChatMessageAttachmentField[]
{
            new SlackChatMessageAttachmentField
            {
                Title =  "Message Attachment Title",
            	Value =  "Message Attachment Value"
            }
};
var postMessageResult = Slack.Chat.PostMessage(
	channel:slackChannel,
	text:"Starting Cake Build...",
	messageAttachments:new SlackChatMessageAttachment[]
	{
	            new SlackChatMessageAttachment
	            {
	                        Text = "Cake Text",
	                        Pretext = "Cake Pretext",
	                        Color = "#67A0E1",
	                        Fields = slackAssemblyFieldAttachment
	            }
     },
	messageSettings:new SlackChatMessageSettings { IncomingWebHookUrl = slackWebHookUrl });

if (postMessageResult.Ok)
{
    Information("Message successfully sent");
}
else
{
    Error("Failed to send message: {0}", postMessageResult.Error);
}

This will result in a message in your Slack channel similar to below:

Sample message attachment