-
-
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 objects, list of all
tasks, and an error that stopped a build.
The command for getting results looks like
Invoke-Build ... -Result Result
It tells to create the variable $Result
populated with build data.
See help:
Get-Help Invoke-Build -Parameter Result
The list $Result.Errors
contains objects:
-
Error
- original error record -
File
- current$BuildFile
-
Task
- current$Task
or null for non-task errors
The list $Result.Warnings
contains objects:
-
Message
- warning message -
File
- current$BuildFile
-
Task
- current$Task
or null for non-task warnings
Analysis of errors and warnings is especially useful in testing scenarios when
several build scripts *.test.ps1
are invoked:
Invoke-Build ** -Safe -Result Result
In order to get errors by tasks iterate through $Result.Tasks
and check their
Error
. 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