diff --git a/en-US/psake.psm1-help.xml b/en-US/psake.psm1-help.xml
index 0ce5cd2..3fba9ce 100644
--- a/en-US/psake.psm1-help.xml
+++ b/en-US/psake.psm1-help.xml
@@ -167,7 +167,7 @@ Possible values: '1.0', '1.1', '2.0', '2.0x86', '2.0x64', '3.0', '3.0x86', '3.0x
---- Exceptions ----
- If there is an exception thrown during the running of a build script and the build script was invoked by a windows service then psake will execute the "exit" command (with a default value of "1") which in turn sets the PowerShell $lastexitcode variable otherwise psake will set the '$psake.build_success' variable to $true or $false depending on whether an exception was thrown.
+ If there is an exception thrown during the running of a build script psake will set the '$psake.build_success' variable to $false. To detect failue outside PowerShell (for example by build server), finish PowerShell process with non-zero exit code when '$psake.build_success' is $false. Calling psake from 'cmd.exe' with 'psake.cmd' will give you that behaviour.
diff --git a/psake-config.ps1 b/psake-config.ps1
index b6cd8de..4fb966b 100644
--- a/psake-config.ps1
+++ b/psake-config.ps1
@@ -5,7 +5,6 @@ Defaults
$config.defaultBuildFileName="default.ps1";
$config.framework = "3.5";
$config.taskNameFormat="Executing {0}";
-$config.exitCode="1";
$config.verboseError=$true;
$config.coloredOutput = $true;
$config.modules=(new-object psobject -property @{ autoload=$false })
@@ -29,4 +28,4 @@ $config.modules=(new-object psobject -property @{
(new-object psobject -property @{path="c:\module1dir\module2.ps1"})
})
}
-#>
\ No newline at end of file
+#>
diff --git a/psake.cmd b/psake.cmd
index 3e9649b..114df9b 100644
--- a/psake.cmd
+++ b/psake.cmd
@@ -8,8 +8,8 @@ if '%1'=='?' goto usage
if '%1'=='/help' goto usage
if '%1'=='help' goto usage
-powershell -NoProfile -ExecutionPolicy unrestricted -Command "& '%DIR%psake.ps1' %*"
+powershell -NoProfile -ExecutionPolicy unrestricted -Command "& '%DIR%psake.ps1' %*; if ($psake.build_success -eq $false) { exit 1 }"
goto :eof
:usage
-powershell -NoProfile -ExecutionPolicy unrestricted -Command "& '%DIR%psake-help.ps1'"
\ No newline at end of file
+powershell -NoProfile -ExecutionPolicy unrestricted -Command "& '%DIR%psake-help.ps1'"
diff --git a/psake.ps1 b/psake.ps1
index 0940cf3..51d74fe 100644
--- a/psake.ps1
+++ b/psake.ps1
@@ -5,33 +5,31 @@
# Must match parameter definitions for psake.psm1/invoke-psake
# otherwise named parameter binding fails
param(
- [Parameter(Position=0,Mandatory=0)]
- [string]$buildFile = 'default.ps1',
- [Parameter(Position=1,Mandatory=0)]
- [string[]]$taskList = @(),
- [Parameter(Position=2,Mandatory=0)]
- [string]$framework,
- [Parameter(Position=3,Mandatory=0)]
- [switch]$docs = $false,
- [Parameter(Position=4,Mandatory=0)]
- [System.Collections.Hashtable]$parameters = @{},
- [Parameter(Position=5, Mandatory=0)]
- [System.Collections.Hashtable]$properties = @{},
- [Parameter(Position=6, Mandatory=0)]
- [string]$scriptPath = $(Split-Path -parent $MyInvocation.MyCommand.path),
- [Parameter(Position=7, Mandatory=0)]
- [switch]$nologo = $false
+ [Parameter(Position=0,Mandatory=0)]
+ [string]$buildFile = 'default.ps1',
+ [Parameter(Position=1,Mandatory=0)]
+ [string[]]$taskList = @(),
+ [Parameter(Position=2,Mandatory=0)]
+ [string]$framework,
+ [Parameter(Position=3,Mandatory=0)]
+ [switch]$docs = $false,
+ [Parameter(Position=4,Mandatory=0)]
+ [System.Collections.Hashtable]$parameters = @{},
+ [Parameter(Position=5, Mandatory=0)]
+ [System.Collections.Hashtable]$properties = @{},
+ [Parameter(Position=6, Mandatory=0)]
+ [string]$scriptPath = $(Split-Path -parent $MyInvocation.MyCommand.path),
+ [Parameter(Position=7, Mandatory=0)]
+ [switch]$nologo = $false
)
remove-module psake -ea 'SilentlyContinue'
import-module (join-path $scriptPath psake.psm1)
-if (-not(test-path $buildFile))
-{
+if (-not(test-path $buildFile)) {
$absoluteBuildFile = (join-path $scriptPath $buildFile)
- if (test-path $absoluteBuildFile)
- {
- $buildFile = $absoluteBuildFile
- }
+ if (test-path $absoluteBuildFile) {
+ $buildFile = $absoluteBuildFile
+ }
}
+
invoke-psake $buildFile $taskList $framework $docs $parameters $properties $nologo
-exit $lastexitcode
\ No newline at end of file
diff --git a/psake.psm1 b/psake.psm1
index a0090f1..a4ce202 100644
--- a/psake.psm1
+++ b/psake.psm1
@@ -386,12 +386,7 @@ function Invoke-psake {
} else {
Write-ColoredOutput $error_message -foregroundcolor Red
}
-
- # Need to return a non-zero DOS exit code so that CI server's (Hudson, TeamCity, etc...) can detect a failed job
- if ((IsChildOfService)) {
- $host.SetShouldExit($currentConfig.exitCode)
- exit($currentConfig.exitCode)
- }
+
}
} finally {
Cleanup-Environment
@@ -490,7 +485,6 @@ function Create-ConfigurationForNewContext {
buildFileName = $previousConfig.buildFileName;
framework = $previousConfig.framework;
taskNameFormat = $previousConfig.taskNameFormat;
- exitCode = $previousConfig.exitCode;
verboseError = $previousConfig.verboseError;
coloredOutput = $previousConfig.coloredOutput;
modules = $previousConfig.modules
@@ -507,29 +501,6 @@ function Create-ConfigurationForNewContext {
return $config
}
-function IsChildOfService {
- param(
- [int] $currentProcessID = $PID
- )
-
- $currentProcess = gwmi -Query "select * from win32_process where processid = '$currentProcessID'"
-
- #System Idle Process
- if ($currentProcess.ProcessID -eq 0) {
- return $false
- }
-
- $service = Get-WmiObject -Class Win32_Service -Filter "ProcessId = '$currentProcessID'"
-
- #We are invoked by a windows service
- if ($service) {
- return $true
- } else {
- $parentProcess = gwmi -Query "select * from win32_process where processid = '$($currentProcess.ParentProcessID)'"
- return IsChildOfService $parentProcess.ProcessID
- }
-}
-
function Configure-BuildEnvironment {
$framework = $psake.context.peek().config.framework
if ($framework.Length -ne 3 -and $framework.Length -ne 6) {
@@ -714,7 +685,6 @@ $psake.config_default = new-object psobject -property @{
buildFileName = "default.ps1";
framework = "3.5";
taskNameFormat = "Executing {0}";
- exitCode = "1";
verboseError = $false;
coloredOutput = $true;
modules = (new-object PSObject -property @{
@@ -728,4 +698,4 @@ $psake.build_script_dir = "" # contains a string with fully-qualified path to cu
Load-Configuration
-export-modulemember -function invoke-psake, invoke-task, task, properties, include, formattaskname, tasksetup, taskteardown, framework, assert, exec -variable psake
+export-modulemember -function invoke-psake, invoke-task, task, properties, include, formattaskname, tasksetup, taskteardown, framework, assert, exec -variable psake
diff --git a/specs/writing_psake_variables_should_pass.ps1 b/specs/writing_psake_variables_should_pass.ps1
index 2dcd345..21be2f9 100644
--- a/specs/writing_psake_variables_should_pass.ps1
+++ b/specs/writing_psake_variables_should_pass.ps1
@@ -28,7 +28,6 @@ task Verify -description "This task verifies psake's variables" {
Assert ((new-object "System.IO.FileInfo" $config.buildFileName).FullName -eq $psake.build_script_file.FullName) ('$psake.context.peek().config.buildFileName not equal to "{0}"' -f $psake.build_script_file.FullName)
Assert ($config.framework -eq "3.5") '$psake.context.peek().config.framework not equal to "3.5"'
Assert ($config.taskNameFormat -eq "Executing {0}") '$psake.context.peek().config.taskNameFormat not equal to "Executing {0}"'
- Assert ($config.exitCode -eq "1") '$psake.context.peek().config.ExitCode not equal to "1"'
Assert (!$config.verboseError) '$psake.context.peek().config.verboseError should be $false'
Assert ($config.coloredOutput) '$psake.context.peek().config.coloredOutput should be $false'
Assert ($config.modules) '$psake.context.peek().config.modules is $null'