forked from OctopusDeploy/OctopusDSC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsurface-logs.ps1
73 lines (64 loc) · 2.48 KB
/
surface-logs.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Function Get-ConfigPath
{
$ConfigPaths = @()
if( (Test-Path "C:\ProgramData\Octopus\OctopusServer\Instances"))
{
$files = Get-ChildItem "C:\ProgramData\Octopus\OctopusServer\Instances" -filter "*.config"
if($null -ne $files)
{
$files | ForEach-Object {
$Config = Get-Content $_.FullName | ConvertFrom-Json
write-host "adding '$($Config.ConfigurationFilePath)'"
$ConfigPaths += $Config.ConfigurationFilePath
}
}
}
if( (Test-Path "HKLM:\SOFTWARE\Octopus\OctopusServer\"))
{
Get-ChildItem "HKLM:\SOFTWARE\Octopus\OctopusServer\" | ForEach-Object {
$_ | ForEach-Object {
write-host "adding '$(Get-ItemProperty $_.PSPath | select -expand Configurationfilepath)'"
$ConfigPaths += Get-ItemProperty $_.PSPath | select -expand Configurationfilepath
}
}
}
if( (Test-Path "HKLM:\SOFTWARE\Octopus\Tentacle\" ) )
{
Get-ChildItem "HKLM:\SOFTWARE\Octopus\Tentacle\" | ForEach-Object {
$_ | ForEach-Object {
write-host "adding '$(Get-ItemProperty $_.PSPath | select -expand Configurationfilepath)'"
$ConfigPaths += Get-ItemProperty -Path $_.PSPath | select -expand Configurationfilepath
}
}
}
return , $ConfigPaths | select -Unique | where-object { $null -ne $_ }
}
Function Get-LogPath
{
param([string[]]$ConfigPaths)
$LogPaths = @()
$ConfigPaths | ForEach-Object {
$ConfigXML = [xml](Get-Content $_ )
$Homepath = $ConfigXML.SelectSingleNode('/octopus-settings/set[@key="Octopus.Home"]/text()').Value
$LogPath = "$Homepath\Logs"
$LogPaths += $LogPath
}
return $LogPaths
}
Write-Host "##teamcity[blockOpened name='Log Files']"
$configPaths = Get-ConfigPath
$configPaths | ForEach-Object {
$configPath = $_
Write-Host "##teamcity[blockOpened name='Config File $($configPath)']"
Get-Content $configPath | Write-Host
Write-Host "##teamcity[blockClosed name='Config File $($configPath)']"
}
Get-LogPath -ConfigPaths $configPaths | ForEach-Object {
Get-ChildItem $_ -filter "*.txt" | ForEach-Object {
$LogPath = $_.FullName
Write-Host "##teamcity[blockOpened name='Log File $($LogPath)']"
Get-Content $LogPath | Write-Host
Write-Host "##teamcity[blockClosed name='Log File $($LogPath)']"
}
}
Write-Host "##teamcity[blockClosed name='Log Files']"