Skip to content

Octopus Deploy in Your Cake (C# Make)

Sponsor: Do you build complex software systems? See how NServiceBus makes it easier to design, build, and manage software systems that use message queues to achieve loose coupling. Get started for free.

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.

4 thoughts on “Octopus Deploy in Your Cake (C# Make)”

  1. Great article! Thank you for sharing your experiences with the community! Quick question… You mentioned that you are using the Cake.ExtendedNuGet package, but none of the code samples that you have shown are actually using it. All the methods that you show are those built into Cake. Can you confirm which aliases that are provided within the Cake.ExtendedNuGet package you are actually using? Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *