Improve how Linux container CI builds are identified (#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 b900e1231b.

* conditionally set build name and add tag

* Pass title prefix

* don't add tag when the build is a PR

* use correct variable name
This commit is contained in:
Travis Plunk 2022-05-10 10:09:51 -07:00 committed by GitHub
parent ee97dfe412
commit 34f316db1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 13 deletions

View File

@ -153,6 +153,15 @@ stages:
Import-Module ./PowerShell/tools/ci.psm1
Set-BuildVariable -Name containerName -Value $containerName -IsOutput
Set-BuildVariable -Name containerBuildName -Value $selectedImage.JobName -IsOutput
if($env:BUILD_REASON -eq 'PullRequest') {
Write-Host "##vso[build.updatebuildnumber]PR-$(System.PullRequest.PullRequestNumber)-$($selectedImage.JobName)-$((get-date).ToString("yyyyMMddhhmmss"))"
} else {
Write-Host "##vso[build.updatebuildnumber]${env:BUILD_SOURCEBRANCHNAME}-${env:BUILD_SOURCEVERSION}-$($selectedImage.JobName)-$((get-date).ToString("yyyyMMddhhmmss"))"
# Cannot do this for a PR
Write-Host "##vso[build.addbuildtag]$($selectedImage.JobName)"
}
name: getContainerTask
displayName: Get Container
continueOnError: true

View File

@ -11,8 +11,9 @@ jobs:
- getContainerJob
variables:
getContainerJob: $[ dependencies.getContainerJob.outputs['getContainerTask.containerName'] ]
__INCONTAINER: 1
getContainerJob: $[ dependencies.getContainerJob.outputs['getContainerTask.containerName'] ]
containerBuildName: $[ dependencies.getContainerJob.outputs['getContainerTask.containerBuildName'] ]
container: $[ variables.getContainerJob ]
@ -26,3 +27,4 @@ jobs:
parameters:
purpose: ${{ parameters.purpose }}
tagSet: ${{ parameters.tagSet }}
buildName: $(containerBuildName)

View File

@ -1,6 +1,7 @@
parameters:
purpose: ''
tagSet: 'CI'
buildName: 'Ubuntu'
steps:
- pwsh: |
@ -54,6 +55,6 @@ steps:
chmod a+x $pwshPath
$options.Output = $pwshPath
Set-PSOptions $options
Invoke-CITest -Purpose '${{ parameters.purpose }}' -TagSet '${{ parameters.tagSet }}'
Invoke-CITest -Purpose '${{ parameters.purpose }}' -TagSet '${{ parameters.tagSet }}' -TitlePrefix '${{ parameters.buildName }}'
displayName: Test
condition: succeeded()

View File

@ -219,7 +219,8 @@ function Invoke-CITest
[ValidateSet('UnelevatedPesterTests', 'ElevatedPesterTests')]
[string] $Purpose,
[ValidateSet('CI', 'Others')]
[string] $TagSet
[string] $TagSet,
[string] $TitlePrefix
)
# Set locale correctly for Linux CIs
@ -244,7 +245,7 @@ function Invoke-CITest
if($IsLinux -or $IsMacOS)
{
return Invoke-LinuxTestsCore -Purpose $Purpose -ExcludeTag $ExcludeTag -TagSet $TagSet
return Invoke-LinuxTestsCore -Purpose $Purpose -ExcludeTag $ExcludeTag -TagSet $TagSet -TitlePrefix $TitlePrefix
}
# CoreCLR
@ -271,7 +272,12 @@ function Invoke-CITest
ExcludeTag = $ExcludeTag + 'RequireAdminOnWindows'
}
Start-PSPester @arguments -Title "Pester Unelevated - $TagSet"
$title = "Pester Unelevated - $TagSet"
if ($TitlePrefix) {
$title = "$TitlePrefix - $title"
}
Start-PSPester @arguments -Title $title
# Fail the build, if tests failed
Test-PSPesterResults -TestResultsFile $testResultsNonAdminFile
@ -293,7 +299,11 @@ function Invoke-CITest
$arguments['Path'] = $testFiles
}
Start-PSPester @arguments -Title "Pester Experimental Unelevated - $featureName"
$title = "Pester Experimental Unelevated - $featureName"
if ($TitlePrefix) {
$title = "$TitlePrefix - $title"
}
Start-PSPester @arguments -Title $title
# Fail the build, if tests failed
Test-PSPesterResults -TestResultsFile $expFeatureTestResultFile
@ -309,7 +319,11 @@ function Invoke-CITest
ExcludeTag = $ExcludeTag
}
Start-PSPester @arguments -Title "Pester Elevated - $TagSet"
$title = "Pester Elevated - $TagSet"
if ($TitlePrefix) {
$title = "$TitlePrefix - $title"
}
Start-PSPester @arguments -Title $title
# Fail the build, if tests failed
Test-PSPesterResults -TestResultsFile $testResultsAdminFile
@ -334,7 +348,12 @@ function Invoke-CITest
# If a non-empty string or array is specified for the feature name, we only run those test files.
$arguments['Path'] = $testFiles
}
Start-PSPester @arguments -Title "Pester Experimental Elevated - $featureName"
$title = "Pester Experimental >levated - $featureName"
if ($TitlePrefix) {
$title = "$TitlePrefix - $title"
}
Start-PSPester @arguments -Title $title
# Fail the build, if tests failed
Test-PSPesterResults -TestResultsFile $expFeatureTestResultFile
@ -612,7 +631,8 @@ function Invoke-LinuxTestsCore
[ValidateSet('UnelevatedPesterTests', 'ElevatedPesterTests', 'All')]
[string] $Purpose = 'All',
[string[]] $ExcludeTag = @('Slow', 'Feature', 'Scenario'),
[string] $TagSet = 'CI'
[string] $TagSet = 'CI',
[string] $TitlePrefix
)
$output = Split-Path -Parent (Get-PSOutput -Options (Get-PSOptions))
@ -639,7 +659,11 @@ function Invoke-LinuxTestsCore
# Running tests which do not require sudo.
if($Purpose -eq 'UnelevatedPesterTests' -or $Purpose -eq 'All')
{
$pesterPassThruNoSudoObject = Start-PSPester @noSudoPesterParam -Title "Pester No Sudo - $TagSet"
$title = "Pester No Sudo - $TagSet"
if ($TitlePrefix) {
$title = "$TitlePrefix - $title"
}
$pesterPassThruNoSudoObject = Start-PSPester @noSudoPesterParam -Title $title
# Running tests that do not require sudo, with specified experimental features enabled
$noSudoResultsWithExpFeatures = @()
@ -660,7 +684,12 @@ function Invoke-LinuxTestsCore
# If a non-empty string or array is specified for the feature name, we only run those test files.
$noSudoPesterParam['Path'] = $testFiles
}
$passThruResult = Start-PSPester @noSudoPesterParam -Title "Pester Experimental No Sudo - $featureName - $TagSet"
$title = "Pester Experimental No Sudo - $featureName - $TagSet"
if ($TitlePrefix) {
$title = "$TitlePrefix - $title"
}
$passThruResult = Start-PSPester @noSudoPesterParam -Title $title
$noSudoResultsWithExpFeatures += $passThruResult
}
}
@ -674,7 +703,12 @@ function Invoke-LinuxTestsCore
$sudoPesterParam['ExcludeTag'] = $ExcludeTag
$sudoPesterParam['Sudo'] = $true
$sudoPesterParam['OutputFile'] = $testResultsSudo
$pesterPassThruSudoObject = Start-PSPester @sudoPesterParam -Title "Pester Sudo - $TagSet"
$title = "Pester Sudo - $TagSet"
if ($TitlePrefix) {
$title = "$TitlePrefix - $title"
}
$pesterPassThruSudoObject = Start-PSPester @sudoPesterParam -Title $title
# Running tests that require sudo, with specified experimental features enabled
$sudoResultsWithExpFeatures = @()
@ -696,7 +730,13 @@ function Invoke-LinuxTestsCore
# If a non-empty string or array is specified for the feature name, we only run those test files.
$sudoPesterParam['Path'] = $testFiles
}
$passThruResult = Start-PSPester @sudoPesterParam -Title "Pester Experimental Sudo - $featureName - $TagSet"
$title = "Pester Experimental Sudo - $featureName - $TagSet"
if ($TitlePrefix) {
$title = "$TitlePrefix - $title"
}
$passThruResult = Start-PSPester @sudoPesterParam -Title $title
$sudoResultsWithExpFeatures += $passThruResult
}
}