Halting build on first assertion in nested script

21 views
Skip to first unread message

Ronnie Holm

unread,
Dec 28, 2011, 8:20:05 AM12/28/11
to psake-users
Suppose I have the following psake script:

--- begin foo.ps1 ---
function FunctionWithFailingAssertion() {
('a', 'b', 'c') | foreach {
assert $false "Some assertion failure $_"
}
}

task task1 {
FunctionWithFailingAssertion
}
--- end foo.ps1 ---

Now when I invoke task1:

$> invoke-psake .\foo.ps1 task1
Executing task: task1
foo.ps1:Some assertion failure a

psake fails as expected.

But suppose foo.ps1 is a nested script called from bar.ps1:

--- begin bar.ps1 ---
task task2 {
Invoke-psake .\foo.ps1 task1
Invoke-psake .\foo.ps1 task1
}
--- end bar.ps1 ---

Now psake doesn't behave as I'd expect:

$> Invoke-psake bar.ps1 task2
Executing task: task2
Executing task: task1
foo.ps1:Some assertion failure a
Executing task: task1
foo.ps1:Some assertion failure a

Build Succeeded!

There were two assertion failures, yet the build was successful. The
behavior I'm looking for is for psake to halt execution when it
encounters the first assertion failure.

What's the best way to accomplish this? Should I wrap every call to
invoke-psake in code that checks if an error has occurred?

Ronnie
Reply all
Reply to author
Forward
0 new messages