Skip to content

Commit 34f316d

Browse files
authored
Improve how Linux container CI builds are identified (PowerShell#17295)
* Add buildName preview to Jobs and tests * try other syntax * give up on task name * try naming the job again * use other syntax for variable * rename and tag build * Revert "try naming the job again" This reverts commit b900e12. * conditionally set build name and add tag * Pass title prefix * don't add tag when the build is a PR * use correct variable name
1 parent ee97dfe commit 34f316d

File tree

4 files changed

+65
-13
lines changed

4 files changed

+65
-13
lines changed

.vsts-ci/linux.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ stages:
153153
Import-Module ./PowerShell/tools/ci.psm1
154154
Set-BuildVariable -Name containerName -Value $containerName -IsOutput
155155
Set-BuildVariable -Name containerBuildName -Value $selectedImage.JobName -IsOutput
156+
157+
if($env:BUILD_REASON -eq 'PullRequest') {
158+
Write-Host "##vso[build.updatebuildnumber]PR-$(System.PullRequest.PullRequestNumber)-$($selectedImage.JobName)-$((get-date).ToString("yyyyMMddhhmmss"))"
159+
} else {
160+
Write-Host "##vso[build.updatebuildnumber]${env:BUILD_SOURCEBRANCHNAME}-${env:BUILD_SOURCEVERSION}-$($selectedImage.JobName)-$((get-date).ToString("yyyyMMddhhmmss"))"
161+
162+
# Cannot do this for a PR
163+
Write-Host "##vso[build.addbuildtag]$($selectedImage.JobName)"
164+
}
156165
name: getContainerTask
157166
displayName: Get Container
158167
continueOnError: true

.vsts-ci/templates/test/nix-container-test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ jobs:
1111
- getContainerJob
1212

1313
variables:
14-
getContainerJob: $[ dependencies.getContainerJob.outputs['getContainerTask.containerName'] ]
1514
__INCONTAINER: 1
15+
getContainerJob: $[ dependencies.getContainerJob.outputs['getContainerTask.containerName'] ]
16+
containerBuildName: $[ dependencies.getContainerJob.outputs['getContainerTask.containerBuildName'] ]
1617

1718
container: $[ variables.getContainerJob ]
1819

@@ -26,3 +27,4 @@ jobs:
2627
parameters:
2728
purpose: ${{ parameters.purpose }}
2829
tagSet: ${{ parameters.tagSet }}
30+
buildName: $(containerBuildName)

.vsts-ci/templates/test/nix-test-steps.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
parameters:
22
purpose: ''
33
tagSet: 'CI'
4+
buildName: 'Ubuntu'
45

56
steps:
67
- pwsh: |
@@ -54,6 +55,6 @@ steps:
5455
chmod a+x $pwshPath
5556
$options.Output = $pwshPath
5657
Set-PSOptions $options
57-
Invoke-CITest -Purpose '${{ parameters.purpose }}' -TagSet '${{ parameters.tagSet }}'
58+
Invoke-CITest -Purpose '${{ parameters.purpose }}' -TagSet '${{ parameters.tagSet }}' -TitlePrefix '${{ parameters.buildName }}'
5859
displayName: Test
5960
condition: succeeded()

tools/ci.psm1

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ function Invoke-CITest
219219
[ValidateSet('UnelevatedPesterTests', 'ElevatedPesterTests')]
220220
[string] $Purpose,
221221
[ValidateSet('CI', 'Others')]
222-
[string] $TagSet
222+
[string] $TagSet,
223+
[string] $TitlePrefix
223224
)
224225

225226
# Set locale correctly for Linux CIs
@@ -244,7 +245,7 @@ function Invoke-CITest
244245

245246
if($IsLinux -or $IsMacOS)
246247
{
247-
return Invoke-LinuxTestsCore -Purpose $Purpose -ExcludeTag $ExcludeTag -TagSet $TagSet
248+
return Invoke-LinuxTestsCore -Purpose $Purpose -ExcludeTag $ExcludeTag -TagSet $TagSet -TitlePrefix $TitlePrefix
248249
}
249250

250251
# CoreCLR
@@ -271,7 +272,12 @@ function Invoke-CITest
271272
ExcludeTag = $ExcludeTag + 'RequireAdminOnWindows'
272273
}
273274

274-
Start-PSPester @arguments -Title "Pester Unelevated - $TagSet"
275+
$title = "Pester Unelevated - $TagSet"
276+
if ($TitlePrefix) {
277+
$title = "$TitlePrefix - $title"
278+
}
279+
Start-PSPester @arguments -Title $title
280+
275281
# Fail the build, if tests failed
276282
Test-PSPesterResults -TestResultsFile $testResultsNonAdminFile
277283

@@ -293,7 +299,11 @@ function Invoke-CITest
293299
$arguments['Path'] = $testFiles
294300
}
295301

296-
Start-PSPester @arguments -Title "Pester Experimental Unelevated - $featureName"
302+
$title = "Pester Experimental Unelevated - $featureName"
303+
if ($TitlePrefix) {
304+
$title = "$TitlePrefix - $title"
305+
}
306+
Start-PSPester @arguments -Title $title
297307

298308
# Fail the build, if tests failed
299309
Test-PSPesterResults -TestResultsFile $expFeatureTestResultFile
@@ -309,7 +319,11 @@ function Invoke-CITest
309319
ExcludeTag = $ExcludeTag
310320
}
311321

312-
Start-PSPester @arguments -Title "Pester Elevated - $TagSet"
322+
$title = "Pester Elevated - $TagSet"
323+
if ($TitlePrefix) {
324+
$title = "$TitlePrefix - $title"
325+
}
326+
Start-PSPester @arguments -Title $title
313327

314328
# Fail the build, if tests failed
315329
Test-PSPesterResults -TestResultsFile $testResultsAdminFile
@@ -334,7 +348,12 @@ function Invoke-CITest
334348
# If a non-empty string or array is specified for the feature name, we only run those test files.
335349
$arguments['Path'] = $testFiles
336350
}
337-
Start-PSPester @arguments -Title "Pester Experimental Elevated - $featureName"
351+
352+
$title = "Pester Experimental >levated - $featureName"
353+
if ($TitlePrefix) {
354+
$title = "$TitlePrefix - $title"
355+
}
356+
Start-PSPester @arguments -Title $title
338357

339358
# Fail the build, if tests failed
340359
Test-PSPesterResults -TestResultsFile $expFeatureTestResultFile
@@ -612,7 +631,8 @@ function Invoke-LinuxTestsCore
612631
[ValidateSet('UnelevatedPesterTests', 'ElevatedPesterTests', 'All')]
613632
[string] $Purpose = 'All',
614633
[string[]] $ExcludeTag = @('Slow', 'Feature', 'Scenario'),
615-
[string] $TagSet = 'CI'
634+
[string] $TagSet = 'CI',
635+
[string] $TitlePrefix
616636
)
617637

618638
$output = Split-Path -Parent (Get-PSOutput -Options (Get-PSOptions))
@@ -639,7 +659,11 @@ function Invoke-LinuxTestsCore
639659
# Running tests which do not require sudo.
640660
if($Purpose -eq 'UnelevatedPesterTests' -or $Purpose -eq 'All')
641661
{
642-
$pesterPassThruNoSudoObject = Start-PSPester @noSudoPesterParam -Title "Pester No Sudo - $TagSet"
662+
$title = "Pester No Sudo - $TagSet"
663+
if ($TitlePrefix) {
664+
$title = "$TitlePrefix - $title"
665+
}
666+
$pesterPassThruNoSudoObject = Start-PSPester @noSudoPesterParam -Title $title
643667

644668
# Running tests that do not require sudo, with specified experimental features enabled
645669
$noSudoResultsWithExpFeatures = @()
@@ -660,7 +684,12 @@ function Invoke-LinuxTestsCore
660684
# If a non-empty string or array is specified for the feature name, we only run those test files.
661685
$noSudoPesterParam['Path'] = $testFiles
662686
}
663-
$passThruResult = Start-PSPester @noSudoPesterParam -Title "Pester Experimental No Sudo - $featureName - $TagSet"
687+
$title = "Pester Experimental No Sudo - $featureName - $TagSet"
688+
if ($TitlePrefix) {
689+
$title = "$TitlePrefix - $title"
690+
}
691+
$passThruResult = Start-PSPester @noSudoPesterParam -Title $title
692+
664693
$noSudoResultsWithExpFeatures += $passThruResult
665694
}
666695
}
@@ -674,7 +703,12 @@ function Invoke-LinuxTestsCore
674703
$sudoPesterParam['ExcludeTag'] = $ExcludeTag
675704
$sudoPesterParam['Sudo'] = $true
676705
$sudoPesterParam['OutputFile'] = $testResultsSudo
677-
$pesterPassThruSudoObject = Start-PSPester @sudoPesterParam -Title "Pester Sudo - $TagSet"
706+
707+
$title = "Pester Sudo - $TagSet"
708+
if ($TitlePrefix) {
709+
$title = "$TitlePrefix - $title"
710+
}
711+
$pesterPassThruSudoObject = Start-PSPester @sudoPesterParam -Title $title
678712

679713
# Running tests that require sudo, with specified experimental features enabled
680714
$sudoResultsWithExpFeatures = @()
@@ -696,7 +730,13 @@ function Invoke-LinuxTestsCore
696730
# If a non-empty string or array is specified for the feature name, we only run those test files.
697731
$sudoPesterParam['Path'] = $testFiles
698732
}
699-
$passThruResult = Start-PSPester @sudoPesterParam -Title "Pester Experimental Sudo - $featureName - $TagSet"
733+
734+
$title = "Pester Experimental Sudo - $featureName - $TagSet"
735+
if ($TitlePrefix) {
736+
$title = "$TitlePrefix - $title"
737+
}
738+
$passThruResult = Start-PSPester @sudoPesterParam -Title $title
739+
700740
$sudoResultsWithExpFeatures += $passThruResult
701741
}
702742
}

0 commit comments

Comments
 (0)