-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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
If you prefer C#:
https://gist.github.com/rpresser/eb63b732932a2e9bcbdd0d7c8c7f9eca