Skip to content

Commit 8099fe6

Browse files
gfraiteurclaude
andcommitted
Add location save/restore to DockerBuild.ps1.
Wrap entire script in Push-Location/Pop-Location with try/finally block to ensure the current directory is restored when the script exits, even if an error occurs. Changes: - Add Push-Location before Set-Location $PSScriptRoot - Wrap script body in try block - Add finally block with Pop-Location at the end This prevents the script from leaving the user in a different directory than where they started. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 0976154 commit 8099fe6

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

DockerBuild.ps1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,13 @@ if ([string]::IsNullOrEmpty($BuildAgentPath))
6262
}
6363
}
6464

65-
Set-Location $PSScriptRoot
65+
# Save current location and restore on exit
66+
Push-Location
67+
try
68+
{
69+
Set-Location $PSScriptRoot
6670

67-
if ($env:IS_TEAMCITY_AGENT)
71+
if ($env:IS_TEAMCITY_AGENT)
6872
{
6973
Write-Host "Running on TeamCity agent at '$BuildAgentPath'" -ForegroundColor Cyan
7074
}
@@ -1339,3 +1343,9 @@ $elapsed = $stopwatch.Elapsed
13391343
Write-Host ""
13401344
Write-Host "Total build time: $($elapsed.ToString('hh\:mm\:ss\.fff') )" -ForegroundColor Cyan
13411345
Write-Host "Build completed at: $( Get-Date -Format 'yyyy-MM-dd HH:mm:ss' )" -ForegroundColor Cyan
1346+
}
1347+
finally
1348+
{
1349+
# Restore original location
1350+
Pop-Location
1351+
}

src/PostSharp.Engineering.BuildTools/Resources/DockerBuild.ps1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,13 @@ if ([string]::IsNullOrEmpty($BuildAgentPath))
6262
}
6363
}
6464

65-
Set-Location $PSScriptRoot
65+
# Save current location and restore on exit
66+
Push-Location
67+
try
68+
{
69+
Set-Location $PSScriptRoot
6670

67-
if ($env:IS_TEAMCITY_AGENT)
71+
if ($env:IS_TEAMCITY_AGENT)
6872
{
6973
Write-Host "Running on TeamCity agent at '$BuildAgentPath'" -ForegroundColor Cyan
7074
}
@@ -1339,3 +1343,9 @@ $elapsed = $stopwatch.Elapsed
13391343
Write-Host ""
13401344
Write-Host "Total build time: $($elapsed.ToString('hh\:mm\:ss\.fff') )" -ForegroundColor Cyan
13411345
Write-Host "Build completed at: $( Get-Date -Format 'yyyy-MM-dd HH:mm:ss' )" -ForegroundColor Cyan
1346+
}
1347+
finally
1348+
{
1349+
# Restore original location
1350+
Pop-Location
1351+
}

0 commit comments

Comments
 (0)