2

I have a build which kicks off a PowerShell script. What it does is gather code coverage metrics and then stores that info in a database. I'd like to pass a value out of that script and back into the build workflow so I can pass or fail the build based on that value.

Any ideas on how I could accomplish that?

1 Answer 1

3

Easiest way is to have PowerShell throw an exception. That will also cause Powershell to return a non-0 exit code. In your InvokeProcess you can either handle the Error stream or have the Result parameter assigned to a variable on your build workflow, then follow that with an if block to pass or fail the build.

Or you can return the coverage outcome using the exit function, it will be assigned to the Result property of the InvokeProcess Activity.

exit 12345;
Sign up to request clarification or add additional context in comments.

4 Comments

Would it be possible to create custom error code, this way I can isolate it from real errors? Hope that made sense.
How about this option? Pass in the coverage threshold value to PowerShell, the coverage process would run, and if the passed in value was less than the result, I could set the build status from within PowerShell.
Sure, that's possible as well, call the exit function from powershell: blogs.msdn.com/b/powershell/archive/2006/10/14/…
This is what I came up with on the PowerShell side: function CoverageResult() { IF ($CoveragePercent -lt $FailurePercent) { Write-Output "Exit Code 10000: $(Get-Date –f $timeStampFormat) - Code Coverage was $CoveragePercent percent, which is below the defined threshold." $Host.SetShouldExit(10000) } ELSE { Write-Output "$(Get-Date –f $timeStampFormat) - Code Coverage was $CoveragePercent percent, which is above the defined threshold. } } Works great! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.