I am trying to get the name of the folder that my package is being extracted to for my Run a Script step. The best way I can figure to do this is to get the name of the package.
I have tried the following variables, but they were all empty when my script runs:
I can go to the release page and see that there is a package there. And when I run Get-ChildItem . in my script I can see the folder for my package is created. (But I am making a template, so I cannot just hard code the folder name.)
How can I get the name of the package (or folder) for my Run a Script step?
If this package is a referenced package within the script step, then you should be able to use the Octopus.Action.Package[Acme].ExtractedPathsystem variable.
The name of the step I am doing my PowerShell script in is called āDeploy Releaseā.
Also, when I run Get-ChildItem . I can see the extracted package in the list of folders. (So I know that the package is there and being extracted. I just need to get its name programmatically.)
The āDeploy Releaseā step is a script step (not a normal IIS type deployment) that is running on a worker. Does a script step on a worker populate different variables than a normal IIS type deployment to a target?
A referenced package within a script step will use different variables to a package within a package deploy step (such as a Deploy to IIS step), but the fact it is running on a worker shouldnāt matter.
The best option may be to add the OctopusPrintEvaluatedVariablessystem variable with a value of true to your project, which will output all available variables to the task log. You should then be able to find the correct one that includes the folder location.
That syntax works! But, now that I have working syntax, I still need a way to get the name of the package, without needing the name of the package.
To clarify, in your example, the name of the package is āRandomQuotesā. But you need to put that in your code (Between the [ ] ) to get the PackageId.
Is there a way to list all the Referenced Packages?
I tried this:
$packages = $OctopusParameters["Octopus.Action.Package"]
foreach ($package in $packages) {
$packageId = $package.PackageId
Write-Output "Package Id = $packageId"
}
But the $packages variable was empty.
I also tried this:
$packageId = $OctopusParameters["Octopus.Action.Package[1].PackageId"]
Write-Output "Package Id = $packageId"
But $packageId was empty.
Is there a way I can list all of the Referenced Packages? (or somehow get my package name without needing my package name to get it?)
Just stepping in for Britton while heās offline, thatās a really great question which unfortunately I havenāt found a great answer for just yet so Iāll definitely be digging into it further.
Our System Variable docs mentions that the Reference package variables are available per package and Iām not able to spot any Action level variables that will give a list of packages so it doesnāt seem possible to use System variables but Iāve asked around for ideas: System variables | Documentation and Support
One potential workaround if the packages are being extracted, would be to grab the package names from the folders being created (by default in the current working directory). E.g
Just an update from the internal discussion, one of the devs provided the following Powershell for using wildcards with our System Variables, so it should work for any type of referenced package:
$keys = $OctopusParameters.Keys | Where {$_ -like "Octopus.Action.Package*.PackageId"}
$packages = $OctopusParameters[$keys]
foreach ($package in $packages) {
Write-Output "Package Id = $package"
}
Feel free to let us know if there are any issues with it or you have any questions at all!