-
-
Notifications
You must be signed in to change notification settings - Fork 59
Build Analysis
The Invoke-Build parameter Result
is used to tell where to store build
results like invoked task objects, error and warning messages, list of all
tasks, and an error that stops a build.
For example, if a build script have tasks which are called safe (job -Safe)
,
then the build may succeed, that is complete without terminating errors, but it
still may have some tasks failed. A caller may want to get this information and
perform some actions on errors:
# Build
Invoke-Build Test Tests.build.ps1 -Result Result
# Analyse the Errors
if ($Result.Errors.Count) {
Write-Warning "Some tests failed."
...
}
else {
Write-Host "All tests succeeded."
...
}
Caution. The list Errors
will continue to exist (so it is safe to use
Errors.Count
) but objects may change in the future. For better and safer
analysis iterate through Tasks
and check their Error
, see below.
Note that Errors
contains raw errors with no related task data. For more
detailed error analysis iterate through Tasks
and check their Error
. In
this way in addition to an error there is useful task information as well:
Name
, InvocationInfo.ScriptName
, and InvocationInfo.ScriptLineNumber
.
foreach($t in $Result.Tasks) {
if ($t.Error) {
"Task '$($t.Name)' at $($t.InvocationInfo.ScriptName):$($t.InvocationInfo.ScriptLineNumber)"
$t.Error
}
}
This code snippet shows all tasks summary after the build (even failed).
try {
# Invoke the build and keep results in the variable Result
Invoke-Build -Result Result
}
finally {
# Show task summary information after the build
$Result.Tasks | Format-Table Elapsed, Name, Error -AutoSize
}
This code snippet shows all tasks ordered by the Elapsed
times and adds task
ScriptName
s to task names (this is useful if different scripts have same task
names, e.g. typical: Build
, Clean
, Test
, ...).
# Invoke the build and keep results in the variable Result
Invoke-Build -Result Result
# Show invoked tasks ordered by Elapsed with ScriptName included
$Result.Tasks |
Sort-Object Elapsed |
Format-Table -AutoSize Elapsed, @{
Name = 'Task'
Expression = {$_.Name + ' @ ' + $_.InvocationInfo.ScriptName}
}
- Concepts
- Script Tutorial
- Incremental Tasks
- Partial Incremental Tasks
- How Build Works
- Special Variables
- Build Failures
- Build Analysis
- Parallel Builds
- Persistent Builds
- Portable Build Scripts
- Using for Test Automation
- Debugging Tips
- VSCode Tips
Helpers
- Invoke Task from VSCode
- Generate VSCode Tasks
- Invoke Task from ISE
- Resolve MSBuild
- Show Build Trees
- Show Build Graph
- Argument Completers
- Invoke-Build.template
Appendix