restore the cwd location even if the build fails
@@ -73,8 +73,6 @@ if ($DepotUrl) {
$env:HAB_DEPOT_URL = "$script:HAB_DEPOT_URL"
# The value of `$env:Path` on initial start of this program
$script:INITIAL_PATH = "$env:Path"
-# The value of `pwd` on initial start of this program
-$script:INITIAL_PWD = "$(Get-Location)"
# The target architecture this plan will be built for
$script:pkg_arch = "x86_64"
# The target system (i.e. operating system variant) this plan will be built for
@@ -222,8 +220,6 @@ function _Get-SystemCommands {
}
-
-
function Write-BuildLine {
<#
.SYNOPSIS
@@ -545,7 +541,7 @@ function Invoke-DefaultBuildService {
Write-BuildLine "Using run hook $PLAN_CONTEXT/hooks/run"
}
else {
- if (Test-Path $pkg_svc_run) {
+ if ($pkg_svc_run -ne "" -and (Test-Path $pkg_svc_run)) {
Write-BuildLine "Writing $pkg_prefix/run script to run $pkg_svc_run"
Set-Content -Path "$pkg_prefix/run" -Value @"
cd "$pkg_svc_path"
@@ -766,15 +762,14 @@ if (-Not (Test-Path "$PLAN_CONTEXT\plan.ps1")) {
}
}
-# Change into the `$PLAN_CONTEXT` directory for proper resolution of relative
-# paths in `plan.ps1`
-Set-Location "$PLAN_CONTEXT"
-# @TODO fin - is there a way to change directory only in this program without
-# affecting the calling powershell session?
-
# We want to fail the build for both termionating and non terminating errors
$ErrorActionPreference = "Stop"
+# Change into the `$PLAN_CONTEXT` directory for proper resolution of relative
+# paths in `plan.ps1`
+Push-Location "$PLAN_CONTEXT"
+
+try {
# Load the Plan
Write-BuildLine "Loading $PLAN_CONTEXT\plan.ps1"
. "$PLAN_CONTEXT\plan.ps1"
@@ -827,7 +822,7 @@ if ("$pkg_prefix" -eq "") {
}
# Determine the final output path for the package artifact
-$script:pkg_output_path = "$INITIAL_PWD\results"
+ $script:pkg_output_path = "$(Get-Location)\results"
# Set $pkg_svc variables a second time, now that the Plan has been sourced and
# we have access to `$pkg_name`.
@@ -909,6 +904,10 @@ _Copy-BuildOutputs
# Cleanup
Write-BuildLine "$program cleanup"
Invoke-End
+}
+finally {
+ Pop-Location
+}
# Print the results
Write-BuildLine
@@ -923,6 +922,3 @@ Write-BuildLine "Blake2b Checksum: $_pkg_blake2bsum"
Write-BuildLine
Write-BuildLine "I love it when a plan.ps1 comes together."
Write-BuildLine
-
-# Return to the original directory
-Set-Location "$INITIAL_PWD"
\ No newline at end of file
