Retrieve "Octo pack --author=xxx" text in Octopus

Hello,
I am creating the package the release and the deploy using Octo.exe from a Jenkins configuration file.
In the Octo.exe pack instructions, I have filled in the property “Author” with my name.
How can I retrieve it in an Octopus?

ex: something like $OctopusParameters[“Octopus.Action.Package.PackageId”] but there is no “Author” field.

Thank you for your time.
Best regards.
L.

Hi, thanks for reaching out.

The easiest way to see what variables are exposed by Octopus is to use the instructions at https://octopus.com/docs/support/debug-problems-with-octopus-variables#DebugproblemswithOctopusvariables-Writethevariablestothedeploymentlog to set the OctopusPrintVariables variable to true. This will then print all the variables known to Octopus to the log file, and you can browse this list to find variables that may be of use to you.

However Octopus does not expose the metadata of a package as a variable. There are two ways around this.

Thr first would be to use the Transfer a Package step to save the Nuget file to a known location, extract the package, and read the nuspec file. For example, if you had a package transfer step called Transfer Package, then the following Powershell script would extract the authors from the samplewebapp.nuspec file.

Add-Type -AssemblyName System.IO.Compression.FileSystem
$file = $OctopusParameters["Octopus.Action[Transfer Package].Output.Package.FilePath"]
$dir = "$($OctopusParameters["Octopus.Action[Transfer Package].Package.TransferPath"])\extracted"
if (Test-Path -Path $dir)
{
  Remove-Item -Recurse -Force $dir
}
New-Item -Path $dir -ItemType directory
[System.IO.Compression.ZipFile]::ExtractToDirectory($file, $dir)
[xml]$XmlDocument = Get-Content -Path "$dir/samplewebapp.nuspec"
Write-Host $XmlDocument.package.metadata.authors

Alternatively if the authors used to build the nuget package are defined as variables from Jenkins, then you can can pass that same variable to Octopus. The Octo CLI create-release command accepts additional variables with the -variable=VALUE arguments. The documentation at https://octopus.com/docs/api-and-integration/octo.exe-command-line/creating-releases has more details. Passing the arguments directly is probably easier than extracting the package and parsing the nuspec file directly.

Regards
Matthew Casperson

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.