Export Octopus Deploy History as CSV
Even so Octopus Deploy stored limited amount of releases history there is an endpoint to export full history which is dramatically helpfull for audit
The script itselft is as simple as
Get-Date
$res = Invoke-RestMethod "https://robota.octopus.app/api/reporting/deployments/xml?apikey=$($env:OCTOPUS_CLI_API_KEY)"
$res = [xml]$res.Substring(1)
Write-Host "Got $($res.Deployments.Deployment.Count) records from OCtopus"
$res.Deployments.Deployment | ConvertTo-Csv -NoTypeInformation | Out-File /Users/mac/Desktop/octopus.csv
Write-Host "Lines in csv: $((Get-Content /Users/mac/Desktop/octopus.csv).Count)"
Get-Date
Which will produce CSV file with something like:
"DeploymentId","DeploymentName","ProjectId","ProjectName","ProjectSlug","TenantId","TenantName","ChannelId","ChannelName","EnvironmentId","EnvironmentName","ReleaseId","ReleaseVersion","TaskId","TaskState","Created","QueueTime","StartTime","CompletedTime","DurationSeconds","DeployedBy"
"Deployments-1","Deploy to Dev","Projects-1","adjwt","adjwt","","","Channels-2","master","Environments-1","dev","Releases-1","1.1.28-b5144e3-master","ServerTasks-421","Success","2018-06-20T13:44:17","2018-06-20T13:44:17","2018-06-20T13:44:17","2018-06-20T13:44:41","24","administrator"
"Deployments-2","Deploy to Dev (#2)","Projects-1","adjwt","adjwt","","","Channels-2","master","Environments-1","dev","Releases-1","1.1.28-b5144e3-master","ServerTasks-422","Success","2018-06-20T13:50:18","2018-06-20T13:50:18","2018-06-20T13:50:18","2018-06-20T13:50:36","18","administrator"