Skip to content

Commit caad18c

Browse files
Copilotjohlju
andcommitted
Add Azure DevOps logging commands for improved pipeline log readability
- Use ##vso[section] for main sections - Use ##vso[task.logissue type=warning] for important decisions - Use ##vso[task.logissue type=debug] for informational messages - Use ##vso[group] for collapsible file lists - Improved visual hierarchy and color coding in Azure Pipelines logs Co-authored-by: johlju <[email protected]>
1 parent c15e72a commit caad18c

File tree

1 file changed

+35
-23
lines changed

1 file changed

+35
-23
lines changed

.build/Test-ShouldRunDscResourceIntegrationTests.ps1

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function Get-PublicCommandsUsedByDscResources
7878

7979
if (-not $publicCommandNames)
8080
{
81-
Write-Warning -Message "No public commands found in $SourcePath/Public"
81+
Write-Host "##vso[task.logissue type=warning]No public commands found in $SourcePath/Public"
8282
return @()
8383
}
8484

@@ -194,12 +194,12 @@ function Get-ChangedFiles
194194
}
195195
}
196196

197-
Write-Warning -Message "Failed to get git diff between $From and $To. Exit code: $LASTEXITCODE. Output: $gitDiffOutput"
197+
Write-Host "##vso[task.logissue type=warning]Failed to get git diff between $From and $To. Exit code: $LASTEXITCODE. Output: $gitDiffOutput"
198198
return @()
199199
}
200200
catch
201201
{
202-
Write-Warning -Message "Error getting changed files: $_"
202+
Write-Host "##vso[task.logissue type=warning]Error getting changed files: $_"
203203
return @()
204204
}
205205
}
@@ -379,35 +379,36 @@ function Test-ShouldRunDscResourceIntegrationTests
379379
$SourcePath = 'source'
380380
)
381381

382+
Write-Host "##vso[section]Analyzing DSC Resource Integration Test Requirements"
382383
Write-Host "Analyzing changes between $BaseBranch and $CurrentBranch..."
383384
Write-Host ""
384385

385386
# Get list of public commands used by DSC resources dynamically
386387
$PublicCommandsUsedByDscResources = Get-PublicCommandsUsedByDscResources -SourcePath $SourcePath
387-
Write-Host "Discovered $($PublicCommandsUsedByDscResources.Count) public commands used by DSC resources and classes."
388+
Write-Host "##vso[task.logissue type=debug]Discovered $($PublicCommandsUsedByDscResources.Count) public commands used by DSC resources and classes."
388389
Write-Host ""
389390

390391
$changedFiles = Get-ChangedFiles -From $BaseBranch -To $CurrentBranch
391392

392393
if (-not $changedFiles)
393394
{
394-
Write-Host "No changed files detected. DSC resource integration tests will run by default."
395+
Write-Host "##vso[task.logissue type=warning]No changed files detected. DSC resource integration tests will run by default."
395396
Write-Host ""
396397
return $true
397398
}
398399

399-
Write-Host "Changed files:"
400+
Write-Host "##vso[group]Changed Files"
400401
$changedFiles | ForEach-Object -Process { Write-Host " $_" }
401-
Write-Host ""
402+
Write-Host "##vso[task.logdetail id=1;progress=100;state=Completed]"
402403

403404
# Check if any DSC resources are directly changed
404405
$changedDscResources = $changedFiles | Where-Object -FilterScript { $_ -match '^source/DSCResources/' -or $_ -match '^source/Classes/' }
405406
if ($changedDscResources)
406407
{
407-
Write-Host "DSC resources or classes have been modified. DSC resource integration tests will run."
408-
Write-Host "Changed DSC resources/classes:"
408+
Write-Host "##vso[task.logissue type=warning]DSC resources or classes have been modified. DSC resource integration tests will run."
409+
Write-Host "##vso[group]Changed DSC Resources/Classes"
409410
$changedDscResources | ForEach-Object -Process { Write-Host " $_" }
410-
Write-Host ""
411+
Write-Host "##vso[task.logdetail id=2;progress=100;state=Completed]"
411412
return $true
412413
}
413414

@@ -418,10 +419,10 @@ function Test-ShouldRunDscResourceIntegrationTests
418419
$affectedCommands = $changedPublicCommands | Where-Object -FilterScript { $_ -in $PublicCommandsUsedByDscResources }
419420
if ($affectedCommands)
420421
{
421-
Write-Host "Public commands used by DSC resources have been modified. DSC resource integration tests will run."
422-
Write-Host "Affected commands:"
422+
Write-Host "##vso[task.logissue type=warning]Public commands used by DSC resources have been modified. DSC resource integration tests will run."
423+
Write-Host "##vso[group]Affected Commands"
423424
$affectedCommands | ForEach-Object -Process { Write-Host " $_" }
424-
Write-Host ""
425+
Write-Host "##vso[task.logdetail id=3;progress=100;state=Completed]"
425426
return $true
426427
}
427428

@@ -447,36 +448,36 @@ function Test-ShouldRunDscResourceIntegrationTests
447448

448449
if ($affectedPrivateFunctions)
449450
{
450-
Write-Host "Private functions used by DSC resource-related public commands or class-based DSC resources have been modified. DSC resource integration tests will run."
451-
Write-Host "Affected private functions:"
451+
Write-Host "##vso[task.logissue type=warning]Private functions used by DSC resource-related public commands or class-based DSC resources have been modified. DSC resource integration tests will run."
452+
Write-Host "##vso[group]Affected Private Functions"
452453
$affectedPrivateFunctions | ForEach-Object -Process { Write-Host " $_" }
453-
Write-Host ""
454+
Write-Host "##vso[task.logdetail id=4;progress=100;state=Completed]"
454455
return $true
455456
}
456457

457458
# Check if integration test files themselves are changed
458459
$changedIntegrationTests = $changedFiles | Where-Object -FilterScript { $_ -match '^tests/Integration/Resources/' }
459460
if ($changedIntegrationTests)
460461
{
461-
Write-Host "DSC resource integration test files have been modified. DSC resource integration tests will run."
462-
Write-Host "Changed integration test files:"
462+
Write-Host "##vso[task.logissue type=warning]DSC resource integration test files have been modified. DSC resource integration tests will run."
463+
Write-Host "##vso[group]Changed Integration Test Files"
463464
$changedIntegrationTests | ForEach-Object -Process { Write-Host " $_" }
464-
Write-Host ""
465+
Write-Host "##vso[task.logdetail id=5;progress=100;state=Completed]"
465466
return $true
466467
}
467468

468469
# Check if pipeline configuration is changed
469470
$changedPipelineFiles = $changedFiles | Where-Object -FilterScript { $_ -match 'azure-pipelines\.yml$|\.build/' }
470471
if ($changedPipelineFiles)
471472
{
472-
Write-Host "Pipeline configuration has been modified. DSC resource integration tests will run."
473-
Write-Host "Changed pipeline files:"
473+
Write-Host "##vso[task.logissue type=warning]Pipeline configuration has been modified. DSC resource integration tests will run."
474+
Write-Host "##vso[group]Changed Pipeline Files"
474475
$changedPipelineFiles | ForEach-Object -Process { Write-Host " $_" }
475-
Write-Host ""
476+
Write-Host "##vso[task.logdetail id=6;progress=100;state=Completed]"
476477
return $true
477478
}
478479

479-
Write-Host "No changes detected that would affect DSC resources. DSC resource integration tests can be skipped."
480+
Write-Host "##vso[task.logissue type=debug]No changes detected that would affect DSC resources. DSC resource integration tests can be skipped."
480481
Write-Host ""
481482
return $false
482483
}
@@ -489,6 +490,17 @@ if ($MyInvocation.InvocationName -ne '.')
489490
# Output result for Azure DevOps variables
490491
Write-Output -InputObject "##vso[task.setvariable variable=ShouldRunDscResourceIntegrationTests]$shouldRun"
491492

493+
# Provide clear final result with appropriate color coding
494+
Write-Host "##vso[section]Test Requirements Decision"
495+
if ($shouldRun)
496+
{
497+
Write-Host "##vso[task.logissue type=warning]RESULT: DSC resource integration tests WILL RUN"
498+
}
499+
else
500+
{
501+
Write-Host "##vso[task.logissue type=debug]RESULT: DSC resource integration tests will be SKIPPED"
502+
}
503+
492504
# Also output as regular output for local testing
493505
Write-Output -InputObject ""
494506
Write-Output -InputObject "ShouldRunDscResourceIntegrationTests: $shouldRun"

0 commit comments

Comments
 (0)