Craftsman at Work

I'm Artur Karbone, coding software architect and independent IT consultant and this is my blog about craftsmanship, architecture, distributed systems, management and much more.

Learn Octopus Deploy Part 7: Anatomy of Built-in Packages Repository

The Octopus Deploy Server has a built-in packages repository. Typically you have to upload your package out there during the build process and reference it later on during the deployment process. There is a variety of options to upload the package.

Manual upload

The most trivial way is to uplad a package manually, via Library->Packages->Upload Package:

alt

By default, the Octopus Web Portal does not allow to overwrite existing packages, but you can force it via Replace this version if it exists.

Library->Packages contains all the packages available in the built-in feed:

alt

Click on a package, to see all the existing versions available:
To see the package's details just click on the version link:

Automated Upload

Since Octopus Deploy is a deployment automation tool, manual deployments is not an option for Continous Integration process. It goes without saying that everything doable via Octopus Web Portal is automatable via API as well. In order to start playing with API, you need to obtain the API key first. Go to Profile -> My API Keys -> NEW API KEY. It is considered a good practice to have a meaningful title for the API key:

alt

When the key is generated it is better to save it in a safe place, since Octopus Deploy can't show you the values later on:
alt

When we've got the key, let's upload some package programmatically. The good news is that Octopus provide examples how to do it out of the box. Goto Libary-> Packages-> Show example how to push packages:

alt

NuGet CLI

Here is how to upload a package via NuGet command:
> nuget push Greeter.API.1.0.0.nupkg -source http://my.octopus:8080/nuget/packages -apikey API-OLRIC1KBDC7PJ5L9RC02WTGAZI

Kind of a similar command dotnet nuget push exists for .NET Core:

dotnet nuget push Greeter.API.1.0.0.nupkg --source http://my.octopus:8080/nuget/packages?replace=true --api-key API-OLRIC1KBDC7PJ5L9RC02WTGAZI

There is an option to replace a package that already exists, btw.

Some resources on how to create a NuGet package:
https://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package
https://www.codeproject.com/Articles/1214420/Creating-a-Nuget-Package-Step-by-Step
https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-visual-studio-net-framework
https://www.hanselman.com/blog/CreatingANuGetPackageIn7EasyStepsPlusUsingNuGetToIntegrateASPNETMVC3IntoExistingWebFormsApplications.aspx
https://octopus.com/docs/packaging-applications/package-repositories/pushing-packages-to-the-built-in-repository

Octo.exe CLI

Another way to create/publish a NuGet package is to use Octo.exe (a CLI or command line interface). Download it from here https://octopus.com/downloads

Create a package (even without having a spec):

octo pack --id Greeter.API

Push the package:

octo push --package Greeter.API.2018.8.5.164906.nupkg --replace-existing --server http://my.octopus:8080 --apiKey API-OLRIC1KBDC7PJ5L9RC02WTGAZI

OctoPack

Just install a nuget package called OctoPack to your project and provide specific CLI options to the msbuild command:
Octopack does not work for .NET Core projects, but is suitable for .NET Framework:
msbuild /t:build /p:RunOctoPack=true /p:OctoPackPackageVersion=4.0.0-beta /p:OctoPackReleaseNotesFile=release.txt /p:OctopackPublishPackageToHttp=http://my.octopus:8080/nuget/packages /p:OctoPackPublishApiKey=API-OLRIC1KBDC7PJ5L9RC02WTGAZI

comments powered by Disqus