rcrowley
(Rcrowley)
22 June 2023 14:28
1
In the script console I would like to be able to refer to a package from the Library, preferably in Powershell, and copy it to some servers. I can’t find any documentation about the command/syntax to refer to library packages.
Hi @rcrowley ,
Welcome to the forums and thank you for contacting Octopus Support.
Here is an example PowerShell script that can download a Package from the built-in feed:
$ErrorActionPreference = "Stop";
# Define working variables
$octopusURL = "https://your.octopus.app"
$octopusAPIKey = "API-YOURAPIKEY"
$header = @{ "X-Octopus-ApiKey" = $octopusAPIKey }
$spaceName = "Default"
$packageName = "packageName"
$packageVersion = "1.0.0.0"
$outputFolder = "/path/to/output/folder"
# Get space
$space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName}
# Get package details
$package = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/packages/packages-$packageName.$packageVersion" -Headers $header)
# Get package
$filePath = [System.IO.Path]::Combine($outputFolder, "$($package.PackageId).$($package.Version)$($package.FileExtension)")
Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/packages/$packageName.$packageVersion/raw" -Headers $header -OutFile $filePath
This file has been truncated. show original
Let me know if this is along the lines of what you are looking for.
Best Regards,
Donny Bell
1 Like
rcrowley
(Rcrowley)
22 June 2023 15:01
4
Thank you. I was able to find the API reference but I was hoping all of that wasn’t necessary if already connected to the script console.
Hi @rcrowley ,
Thank you for getting back to me.
For that, you would need to use a Project as this is not functionality the script console currently has.
Let me know if there is anything else we can assist with.
Best Regards,
Donny Bell
rcrowley
(Rcrowley)
22 June 2023 15:24
6
Thanks again, it does work great!
2 Likes
system
(system)
Closed
23 July 2023 15:25
7
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.