Skip to content

Commit 5afb0ea

Browse files
claudeHeyItsGilbert
authored andcommitted
Address PR feedback: Remove incorrect content
1. Removed "Answer to the original question" callout as requested 2. Removed entire "BuildTearDown for Centralized Reporting" section - BuildSetup and BuildTearDown are not valid psake commands - TaskSetup and TaskTearDown exist but run before/after each task 3. Updated Best Practices Summary to remove BuildTearDown reference 4. Updated Quick Reference table to remove BuildTearDown row 5. Updated See Also links to remove BuildTearDown mention All references to the non-existent BuildSetup/BuildTearDown commands have been removed from the documentation.
1 parent 9970a79 commit 5afb0ea

File tree

1 file changed

+7
-78
lines changed

1 file changed

+7
-78
lines changed

docs/tutorial-advanced/outputs-and-artifacts.md

Lines changed: 7 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ if (Test-Path ./build-output.json) {
8181
exit 0
8282
```
8383

84-
**Answer to the original question:** For your use case of returning a hashtable with an `ArtifactUrl` field, write it to a JSON file as shown above. This is the standard, reliable approach.
85-
8684
#### YAML Output File
8785

8886
```powershell title="psakefile.ps1"
@@ -212,73 +210,6 @@ Task Package -Depends Build {
212210

213211
**When to use:** For passing data between tasks within the same build execution.
214212

215-
### 4. BuildTearDown for Centralized Reporting
216-
217-
Use `BuildTearDown` to generate summary reports or outputs that run after all tasks complete (even on failure).
218-
219-
```powershell title="psakefile.ps1"
220-
# Track build metadata
221-
$script:BuildMetrics = @{
222-
TasksExecuted = @()
223-
StartTime = $null
224-
EndTime = $null
225-
ArtifactUrl = $null
226-
}
227-
228-
BuildSetup {
229-
$script:BuildMetrics.StartTime = Get-Date
230-
}
231-
232-
TaskSetup {
233-
$taskName = $psake.context.Peek().currentTaskName
234-
$script:BuildMetrics.TasksExecuted += $taskName
235-
}
236-
237-
BuildTearDown {
238-
$script:BuildMetrics.EndTime = Get-Date
239-
$duration = $script:BuildMetrics.EndTime - $script:BuildMetrics.StartTime
240-
241-
# Create summary report (IMPORTANT: Write to file, not just variables)
242-
$summary = @{
243-
Success = $psake.build_success
244-
Duration = $duration.TotalSeconds
245-
TasksExecuted = $script:BuildMetrics.TasksExecuted
246-
ArtifactUrl = $script:BuildMetrics.ArtifactUrl
247-
Timestamp = (Get-Date).ToString("o")
248-
}
249-
250-
# Write to file so it's accessible after Invoke-psake completes
251-
$summary | ConvertTo-Json | Set-Content ./build-summary.json
252-
253-
Write-Host "`n========== Build Summary ==========" -ForegroundColor Cyan
254-
Write-Host "Status: $(if ($psake.build_success) { 'SUCCESS' } else { 'FAILED' })"
255-
Write-Host "Duration: $($duration.TotalSeconds) seconds"
256-
Write-Host "Tasks: $($script:BuildMetrics.TasksExecuted -join ', ')"
257-
if ($script:BuildMetrics.ArtifactUrl) {
258-
Write-Host "Artifact: $($script:BuildMetrics.ArtifactUrl)"
259-
}
260-
Write-Host "===================================" -ForegroundColor Cyan
261-
}
262-
263-
Task Build {
264-
exec { dotnet build }
265-
266-
# Store artifact URL for BuildTearDown to include in summary
267-
$script:BuildMetrics.ArtifactUrl = "https://cdn.example.com/builds/1.0.0/app.zip"
268-
}
269-
```
270-
271-
**Pros:**
272-
- Centralized output logic
273-
- Executes regardless of success/failure
274-
- Good for metrics and reporting
275-
276-
**Cons:**
277-
- Only runs after all tasks complete
278-
- **Must write to files** to be accessible after Invoke-psake
279-
280-
**When to use:** For generating build summaries, metrics, or cleanup operations that should always run.
281-
282213
## Anti-Patterns to Avoid
283214

284215
### ❌ Don't Rely on Script Variables Being Accessible Outside psake
@@ -613,13 +544,12 @@ steps:
613544
## Best Practices Summary
614545
615546
1. **Use JSON/YAML output files** - This is the primary recommended approach for returning data
616-
2. **Write to files in BuildTearDown** - Ensures outputs are generated even on failure
617-
3. **Always check exit codes** - They remain the primary success/failure indicator
618-
4. **Use `$script:` variables for inter-task communication** - But understand they're not accessible outside psake
619-
5. **Avoid Write-Host/Write-Output** for structured data - Use files instead
620-
6. **Document your output schema** - So consumers know what to expect
621-
7. **Handle failures gracefully** - Ensure output files contain meaningful error information
622-
8. **Upload output files as CI artifacts** - Makes them available across pipeline stages
547+
2. **Always check exit codes** - They remain the primary success/failure indicator
548+
3. **Use `$script:` variables for inter-task communication** - But understand they're not accessible outside psake
549+
4. **Avoid Write-Host/Write-Output** for structured data - Use files instead
550+
5. **Document your output schema** - So consumers know what to expect
551+
6. **Handle failures gracefully** - Ensure output files contain meaningful error information
552+
7. **Upload output files as CI artifacts** - Makes them available across pipeline stages
623553

624554
## Quick Reference
625555

@@ -628,13 +558,12 @@ steps:
628558
| Return data from psake | JSON output file | `$data \| ConvertTo-Json \| Set-Content output.json` |
629559
| Share data between tasks | Script-scoped variables | `$script:BuildData = @{}` |
630560
| Pass simple strings to CI | Environment variables | `$env:BUILD_VERSION = "1.0.0"` |
631-
| Generate build summary | BuildTearDown + output file | See complete example above |
632561
| Pass data INTO psake | Properties or parameters | `Invoke-psake -properties @{Version="1.0"}` |
633562

634563
## See Also
635564

636565
- [Exit Codes](/docs/reference/exit-codes) - Understanding psake's primary output mechanism
637-
- [Structure of a psake Build Script](/docs/tutorial-advanced/structure-of-a-psake-build-script) - Build script components including BuildTearDown
566+
- [Structure of a psake Build Script](/docs/tutorial-advanced/structure-of-a-psake-build-script) - Build script components
638567
- [Parameters & Properties](/docs/tutorial-basics/parameters-properties) - Passing data INTO builds
639568
- [Build Script Resilience](/docs/tutorial-advanced/build-script-resilience) - Error handling patterns
640569
- [GitHub Actions Integration](/docs/ci-examples/github-actions) - CI/CD examples

0 commit comments

Comments
 (0)