Upload package to Octopus Built-in feed with PowerShell

Although, Octopus docs describes how to do both with REST API and Octopus.Client, I think there are better ways to do it.

I also use PowerShell, but the whole script is much shorter.

$Headers = @{
    "X-Octopus-ApiKey" = $env:OctopusAPIKEY
}

$FormData = @{
    fileData = Get-ChildItem "bckeda-rabbitmq-hpa-0.1.0.tgz"
}

# Upload package to each Octopus Space
@("Spaces-1", "Spaces-2") | % {
    $spaceId = $_
    Invoke-RestMethod `
        -ContentType "multipart/form-data" `
        -Method Post `
        -Uri "https://octopus.mycompany.org/api/$($spaceId)/packages/raw?replace=false" `
        -Form $FormData `
        -Headers $Headers    
}

comments powered by Disqus