I want the user to enter the Project Name, release version and the ENV. Powershell to output the Project Name, Release version, Package, Package Version, package installation path,Date of deployment and the user who has deployed it.
So far I’ve got most of this down accept package installation path and the user.
param (
[Parameter(Mandatory=$true)]
[string]$CheckEnvironment,
[Parameter(Mandatory=$true)]
[string]$releaseVersion,
[Parameter(Mandatory=$true)]
[string]$project_name
)
Add-Type -Path '.\Octopus.Client.dll'
$apikey = 'API-KEY'
$OctopusURI = 'http://servername/'
$endpoint = new-object Octopus.Client.OctopusServerEndpoint $OctopusURI,$apikey
$repository = new-object Octopus.Client.OctopusRepository $endpoint
$project = $repository.Projects.FindByName("$project_name")
$environment = $repository.Environments.FindByName($CheckEnvironment)
$deployments=$repository.Deployments.FindAll()| Where-Object {$_.ProjectId -eq $project.Id}
#put something on the screen
Write-Host "Listing Application releases in environment: $CheckEnvironment"
$msg="Application,Release Number,Package,Package Version,Environment,CompletedTime,Duration,State"
Write-Host $msg
foreach ($d in $deployments)
{
$project=$repository.Projects.Get($d.ProjectId)
$release=$repository.Releases.Get($d.ReleaseId)
$task=$repository.Tasks.Get($d.TaskId)
$environment=$repository.Environments.Get($d.EnvironmentId)
foreach($package in $release.SelectedPackages)
{
if ($release.Version -eq $releaseVersion -and $environment.Name -eq $CheckEnvironment)
{
$msg = $project.Name
$msg = $msg + ", " + $release.Version
$msg = $msg + ", " + $package.ActionName
$msg = $msg + ", " + "Package Version " + $package.version
$msg = $msg + ", " + $environment.Name
$msg = $msg + ", " + $task.CompletedTime
$msg = $msg + ", " + $task.Duration
$msg = $msg + ", " + $task.State
$msg
}
}
}
I found a script on here which can get me the user from the taskid
$serverTasksID = "ServerTasks-12345"
$repository.Events.FindMany(
{param($e) if(($e.Category -match "Queued") -and ($e.RelatedDocumentIds -contains $serverTasksID))
{
#$True # This is optional and returns the entire event object.
Write-Host "The account which :" $e.message ": Was :" $e.username -Verbose
}
})
}
However it takes 30 mins to run, I’m not sure why? Apologies for the long post but is there a way to find the package installation path. Why does getting the username take 30 mins to run?
Thanks