Download all artifacts for a release

I have a project that has 100+ environments in it.
Each environment has 1 - 5 machines in it that need to be patched
When deploying a patch, that patch may generate between 1 - 10 log files that are collected as artifacts, each named as the environment and machine so I know where they came from.

I am trying to find a way that I can download the entire collection for the release in one go (there could be thousands). I can then feed these into an analysis engine.

I have found the resource but this is for a specific deployment. I need something that will download for every deployment in a release.

Can you assist?


Hello all,
I modified the above resource a bit to get the resource below.
It almost gets me what I need.
This gets me all the artifacts from every machine in the release.

Now I have been tasked with getting only the artifacts from those tasks that failed to deploy.

Any ideas?

[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")

$apikey = '' # Get this from your profile
$octopusURI = '' # Your Octopus Server address

$projectName = 'My Project'
$releaseVersion = 'My release'


$octopus = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 
$repository = New-Object Octopus.Client.OctopusRepository $octopus

# HTTP header used for REST-API 
Write-Host "Header..."
$header.Add("X-Octopus-ApiKey", $apikey)

$allProjects = $repository.Projects.FindAll()
$project = $repository.Projects.FindByName($projectName)
$release = $repository.Projects.GetReleaseByVersion($project, $releaseVersion)

# REST Query for artifacts associated with the deployment-id
Write-Host "Query Artifacts..."
$request=$octopusURI + "/api/artifacts?regarding={0}" -f $release.Id
$restResponse=Invoke-RestMethod -Uri $request -Headers $header

$totalItems = $restResponse.TotalResults
$itemsPerPage = $restResponse.ItemsPerPage

Write-Host "List Items ..."
if(!(Test-Path -Path $artifactsDir ))
  New-Item -ItemType directory -Path $artifactsDir | Out-Null

for ($i = 0; $i -lt $totalItems; $i+= $itemsPerPage)
	$request=$octopusURI + "/api/artifacts?regarding={0}&skip={1}" -f $release.Id, $i
	#Write-Host $request -BackgroundColor Yellow
	$restResponse=Invoke-RestMethod -Uri $request -Headers $header
	$items = $restResponse.Items	
	if ($items.Count -gt 0)
		for ($j = 0; $j -lt $items.Length; $j++)
			$artifactURI = $octopusURI + $items[$j].Links.Content
			$artifact = $artifactsDir + "\" + $items[$j].Filename
			Write-Host ("Download[{0}] => [{1}] ..." -f $artifactURI, $artifact)
			$artifactResponse = Invoke-WebRequest -Uri $artifactURI -OutFile $artifact -Headers $header


Write-Host "Finished" -BackgroundColor Green

Hi @imacrae

Thanks for getting in touch! Whilst this could be possible via the API, I think there are better solutions available.

Working with the REST API quickly becomes complicated and often not something we suggest. Where possible we suggest using the Octopus.Client (Some examples) or our SwaggerUI to interract with the API.

However, there is still no preformed script available from us which does what you are after here. I discussed this with our team and we believe the below option is a better alternative to using the REST API.

Instead of collecting these artifacts after the deployment, you could try collecting them at the end. You could use a script at the end of your deployment to copy the artifact to a shared location. You can have Octopus only copy the artifacts if the deployment failed by using our Variable Substitution Syntax and some run conditions (Step only run if the deployment fails). You could then collect the artifacts from this single location.

Let me know if you have any thoughts or questions here.

Best regards,

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.