Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MSBuild target to notify Rollbar of a publish. Requires RollbarSharp web.config entries and git on user's path.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="NotifyRollbarOfDeploy" AfterTargets="MSDeployPublish;CopyAllFilesToSingleFolderForPackage">
<XmlPeek XmlInputPath="$(_PackageTempDir)\web.config"
Query="//appSettings/add[@key='Rollbar.AccessToken']/@value">
<Output TaskParameter="Result" ItemName="RollbarAccessToken" />
</XmlPeek>
<XmlPeek XmlInputPath="$(_PackageTempDir)\web.config"
Query="//appSettings/add[@key='Rollbar.Environment']/@value">
<Output TaskParameter="Result" ItemName="RollbarEnvironment" />
</XmlPeek>
<Exec Command="git log -1 --format=%%H" ConsoleToMSBuild="true" EchoOff="true" WorkingDirectory="$(ProjectDir)\..">
<Output TaskParameter="ConsoleOutput" PropertyName="GitSHA" />
</Exec>
<Exec Command="git config user.email" ConsoleToMSBuild="true" EchoOff="true" WorkingDirectory="$(ProjectDir)\..">
<Output TaskParameter="ConsoleOutput" PropertyName="GitEmail" />
</Exec>
<Message Text="Rollbar.AccessToken: @(RollbarAccessToken)" Importance="Normal" />
<Message Text="Rollbar.Environment: @(RollbarEnvironment)" Importance="Normal" />
<Message Text="Git SHA: $(GitSHA)" Importance="Normal" />
<Message Text="Rollbar: $(GitEmail) deployed @(RollbarEnvironment) revision $(GitSHA)" Importance="High" />
<Exec Command="@powershell -NoProfile -ExecutionPolicy unrestricted -Command &quot;(new-object net.webclient).UploadString('https://api.rollbar.com/api/1/deploy/', 'access_token=@(RollbarAccessToken)&amp;environment=@(RollbarEnvironment)&amp;revision=$(GitSHA)&amp;local_username=$(GitEmail)')&quot;" EchoOff="true" />
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.