Skip to content

Octopus Deploy in Your Cake (C# Make)

Sponsor: Using RabbitMQ or Azure Service Bus in your .NET systems? Well, you could just use their SDKs and roll your own serialization, routing, outbox, retries, and telemetry. I mean, seriously, how hard could it be?

Learn more about Software Architecture & Design.
Join thousands of developers getting weekly updates to increase your understanding of software architecture and design concepts.


Octopus DeployI’ve looked at using Cake (C# Make) for build automation in C#.  The basics were to compile a solution/project using MSBuild and then run our automated tests with xUnit. Another common set of tasks that are performed in a build pipeline are:
  • Create a NuGet package
  • Push the NuGet package to Octopus Deploy
  • Create an Octopus Deploy Release

NuGet

First thing we need to do is to create a NuGet package.  You have a couple options here, one is to create a nuspec and invoke the Nuget.exe to create your package.  I’m going to choose an alternative which is to use the built-in Nuget support to generate our NuGet package all within code. I’ve added a new “Pack” task which is called from our “Default” task.  This task will create our NuGet package when we run our build.ps1
Now when we run our build, we can see the Pack task was created our NuGet package: “CakeDemo.0.0.0.1.nupkg” pack

Octopus Deploy

Cake has built-in support for Octopus Deploy.  To get started, you need to include the OctopusTools in your build.cake file.
#tool "nuget:?package=OctopusTools"
We can use the OctoPush method for pushing your newly created NuGet package to the Octopus Deploy NuGet Server.

Create Release

Now that our NuGet package has been pushed to Octopus Deploy, we can create a release using the OctoCreateRelease method.
To tie this all together, we need to make sure that our Default task will run our OctoPush and OctoRelease tasks.  Here is our final build.cake file
Now when we run our build we can see that our Octopus Deploy release was created. result

More

There are a ton of built-in tasks and the Cake documentation is really good.  Hopefully you can see the benefits of having a build script in code which can be version controlled and run anywhere. Let me know if you have any comments related to Cake or any other build automation tooling either in comments or on twitter.

Source Code

GithubThe source code for this demo is available on GitHub.