Skip to content

Instantly share code, notes, and snippets.

@rirl
Created August 24, 2015 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save rirl/412dd80a5fd85a942139 to your computer and use it in GitHub Desktop.
Save rirl/412dd80a5fd85a942139 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..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment