Skip to content

Instantly share code, notes, and snippets.

@Dalmirog-zz
Forked from rirl/octo-artifacts.ps1
Last active December 18, 2019 19:48
Show Gist options
  • Save Dalmirog-zz/0c446c899ca67de144ad to your computer and use it in GitHub Desktop.
Save Dalmirog-zz/0c446c899ca67de144ad to your computer and use it in GitHub Desktop.
Download ALL artifacts for a given deployment from Octopus Deploy to the artifacts directory
# Try it in powershell...
[Reflection.Assembly]::LoadFile("C:\Program Files\Octopus Deploy\Tentacle\Newtonsoft.Json.dll")
[Reflection.Assembly]::LoadFile("C:\Program Files\Octopus Deploy\Tentacle\Octopus.Client.dll")
[Reflection.Assembly]::LoadFile("C:\Program Files\Octopus Deploy\Tentacle\Octopus.Platform.dll")
# Basic data
Write-Host "Setup..."
$octoKey=" Your API Key"
$octoUser=" Your user name"
$octoId=" Your deployment id, ie (deployments-1492)"
$octoURI=" Base Octopus URL"
#Compose URL
$octoURL=$octoURI+$octoUser
# HTTP header used for REST-API
Write-Host "Header..."
$header=@{}
$header.Add("X-Octopus-ApiKey",$octoKey)
# REST Query for artifacts associated with the deployment-id
Write-Host "Query Artifacts..."
$request=$octoURL+"/api/artifacts?regarding=$octoId"
$restResponse=Invoke-RestMethod -Uri $request -Headers $header
Write-Host "List Items..."
$items=$restResponse.Items
$artifactsDir="artifacts"
if(!(Test-Path -Path $artifactsDir )){
New-Item -ItemType directory -Path $artifactsDir | Out-Null
}
for ($i=0; $i -lt $items.Length; $i++) {
$artifactURI=$octoURI+$items[$i].Links.Content
$artifact=$artifactsDir+"\"+$items[$i].Filename
Write-host ("Download[{0}] => [{1}]..." -f $artifactURI, $artifact)
$artifactResponse=Invoke-WebRequest -Uri $artifactURI -Outfile $artifact -Headers $header
$artifactResponse
}
Write-Host "Finish..."
@rpresser
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment