-
Notifications
You must be signed in to change notification settings - Fork 282
/
helpers.ps1
72 lines (60 loc) · 2.01 KB
/
helpers.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
function OutputLog {
param (
[string]$containerName
)
$logs = Invoke-Command -Script {
$ErrorActionPreference = "silentlycontinue"
docker logs $containerName --tail 250 2>&1
} -ErrorAction SilentlyContinue
Write-Host "---------------- LOGSTART"
Write-Host ($logs -join "`r`n")
Write-Host "---------------- LOGEND"
}
function WaitForLog {
param (
[string]$containerName,
[string]$logContains,
[switch]$extendedTimeout
)
$timeoutSeconds = 20;
if ($extendedTimeout) {
$timeoutSeconds = 60;
}
$timeout = New-TimeSpan -Seconds $timeoutSeconds
$sw = [System.Diagnostics.Stopwatch]::StartNew()
while ($sw.Elapsed -le $timeout) {
Start-Sleep -Seconds 1
$logs = Invoke-Command -Script {
$ErrorActionPreference = "silentlycontinue"
docker logs $containerName --tail 350 2>&1
} -ErrorAction SilentlyContinue
if ($logs -match $logContains) {
return;
}
}
Write-Host "---------------- LOGSTART"
Write-Host ($logs -join "`r`n")
Write-Host "---------------- LOGEND"
Write-Error "Timeout reached without detecting '$($logContains)' in logs after $($sw.Elapsed.TotalSeconds)s"
}
function ThrowIfError() {
if ($LASTEXITCODE -ne 0) {
Write-Error "Last exit code was NOT 0.";
}
}
function HoldBuild() {
# This method should create a file, and hold in a loop with a sleep
# until the file is deleted
# $Env:BUILD_TEMP this is the directory where the file should be crated
# Define the full path for the file
$filePath = Join-Path -Path $Env:BUILD_TEMP -ChildPath "holdbuild.txt"
# Create the file
New-Item -ItemType File -Path $filePath -Force
Write-Host "Created file: $filePath"
# Hold in a loop until the file is deleted
while (Test-Path $filePath) {
Start-Sleep -Seconds 10
Write-Host "Build held until file is deleted: $filePath "
}
Write-Host "File deleted: $filePath"
}