Skip to content

Commit ba6fbe9

Browse files
Start rotating through all images (PowerShell#17315)
* Use day of week for fallback seed * Use new properties to select CI image * move container selection code into * use parameter * fix azDO variable refernce * move container name left in non-PR build name * Use get-command to detect package manager * update dependencies in build.psm1 * Add RHEL to WSMan support function * Update build.psm1 * Update tools/ci.psm1 Co-authored-by: James Truher [MSFT] <jimtru@microsoft.com> Co-authored-by: James Truher [MSFT] <jimtru@microsoft.com>
1 parent e8a5db2 commit ba6fbe9

File tree

4 files changed

+69
-51
lines changed

4 files changed

+69
-51
lines changed

.vsts-ci/linux.yml

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
parameters:
2+
- name: ContainerPattern
3+
displayName: |
4+
Pattern to match JobName of the container.
5+
Update this to force a container.
6+
`.` will match everything
7+
type: string
8+
default: .
9+
110
name: PR-$(System.PullRequest.PullRequestNumber)-$(Date:yyyyMMdd)$(Rev:.rr)
211
trigger:
312
# Batch merge builds together while a merge build is running
@@ -116,54 +125,11 @@ stages:
116125
clean: true
117126

118127
- pwsh: |
119-
$buildId = $env:BUILD_BUILDID
120-
Write-Verbose "Fall back seed: $buildId" -Verbose
121-
# For PRs set the seed to the PR number so that the image is always the same
122-
$seed = $env:SYSTEM_PULLREQUEST_PULLREQUESTID
123-
if(!$seed) {
124-
# for non-PRs use the integer identifier of the build as the seed.
125-
$seed = $buildId
126-
}
127-
Write-Verbose "Seed: $seed" -Verbose
128-
129-
# Get the latest image matrix JSON for preview
130-
$matrix = ./PowerShell-Docker/build.ps1 -GenerateMatrixJson -FullJson -Channel preview | ConvertFrom-Json
131-
132-
# Filter out containers that won't run on AzDevOps Linux host as an agent
133-
# Windows, nano server, alpine, and any ARM image
134-
$linuxImages = $matrix.preview |
135-
Where-Object {$_.osversion -notmatch 'windows|nano|alpine|arm'} |
136-
Select-Object JobName, Taglist |
137-
Sort-Object -property JobName
138-
139-
# Force mariner for now
140-
$marinerImage = $linuxImages | where-object {$_.JobName -like 'mariner*'}
141-
142-
# Use the selected seed to pick a container
143-
$index = Get-Random -Minimum 0 -Maximum $marinerImage.Count -SetSeed $seed
144-
$selectedImage = $marinerImage[$index]
145-
146-
# Filter to the first test-deps compatible tag
147-
$tag = $selectedImage.Taglist -split ';' | Where-Object {$_ -match 'preview-\D+'} | Select-Object -First 1
148-
149-
# Calculate the container name
150-
$containerName = "mcr.microsoft.com/powershell/test-deps:$tag"
151-
152-
# Set variables for later jobs to use
128+
# Initialize container test stage
153129
Import-Module ./PowerShell/tools/ci.psm1
154-
Set-BuildVariable -Name containerName -Value $containerName -IsOutput
155-
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-
}
130+
Invoke-InitializeContainerStage -ContainerPattern '${{ parameters.ContainerPattern }}'
165131
name: getContainerTask
166-
displayName: Get Container
132+
displayName: Initialize Container Stage
167133
continueOnError: true
168134
169135
- template: templates/test/nix-container-test.yml

build.psm1

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,9 +1959,9 @@ function Install-Dotnet {
19591959
}
19601960

19611961
function Get-RedHatPackageManager {
1962-
if ($environment.IsCentOS) {
1962+
if ($environment.IsCentOS -or (Get-Command -Name yum -CommandType Application -ErrorAction SilentlyContinue)) {
19631963
"yum install -y -q"
1964-
} elseif ($environment.IsFedora) {
1964+
} elseif ($environment.IsFedora -or (Get-Command -Name dnf -CommandType Application -ErrorAction SilentlyContinue)) {
19651965
"dnf install -y -q"
19661966
} else {
19671967
throw "Error determining package manager for this distribution."
@@ -2044,7 +2044,6 @@ function Start-PSBootstrap {
20442044
$Deps += "curl", "wget"
20452045

20462046
# .NET Core required runtime libraries
2047-
$Deps += "libunwind8"
20482047
if ($environment.IsUbuntu16) { $Deps += "libicu55" }
20492048
elseif ($environment.IsUbuntu18) { $Deps += "libicu60"}
20502049

@@ -2070,7 +2069,7 @@ function Start-PSBootstrap {
20702069
$Deps += "which", "curl", "wget"
20712070

20722071
# .NET Core required runtime libraries
2073-
$Deps += "libicu", "libunwind"
2072+
$Deps += "libicu", "openssl-libs"
20742073

20752074
# Packaging tools
20762075
if ($Package) { $Deps += "ruby-devel", "rpm-build", "groff", 'libffi-devel', "gcc-c++" }

test/tools/Modules/HelpersCommon/HelpersCommon.psm1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,11 @@ function Get-WsManSupport {
391391
$platformInfo = Get-PlatformInfo
392392
if (
393393
($platformInfo.Platform -match "alpine|raspbian") -or
394-
($platformInfo.Platform -eq "debian" -and $platformInfo.Version -ne '9') -or
394+
($platformInfo.Platform -eq "debian" -and $platformInfo.Version -ne '9') -or
395395
($platformInfo.Platform -eq 'centos' -and $platformInfo.Version -eq '8') -or
396396
($platformInfo.Platform -eq 'ubuntu' -and $platformInfo.Version -eq '20.04') -or
397397
($platformInfo.Platform -eq 'mariner') -or
398+
($platformInfo.Platform -eq 'rhel') -or
398399
($IsMacOS)
399400
) {
400401
return $false

tools/ci.psm1

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,3 +811,55 @@ function New-LinuxPackage
811811
Copy-Item $armPackage -Destination "${env:BUILD_ARTIFACTSTAGINGDIRECTORY}" -Force
812812
}
813813
}
814+
815+
function Invoke-InitializeContainerStage {
816+
param(
817+
[string]
818+
$ContainerPattern = '.'
819+
)
820+
821+
Write-Verbose "Invoking InitializeContainerStage with ContainerPattern: ${ContainerPattern}" -Verbose
822+
823+
$fallbackSeed = (get-date).DayOfYear
824+
Write-Verbose "Fall back seed: $fallbackSeed" -Verbose
825+
826+
# For PRs set the seed to the PR number so that the image is always the same
827+
$seed = $env:SYSTEM_PULLREQUEST_PULLREQUESTID
828+
if(!$seed) {
829+
# for non-PRs use the integer identifier of the build as the seed.
830+
$seed = $fallbackSeed
831+
}
832+
833+
Write-Verbose "Seed: $seed" -Verbose
834+
835+
# Get the latest image matrix JSON for preview
836+
$matrix = ./PowerShell-Docker/build.ps1 -GenerateMatrixJson -FullJson -Channel preview | ConvertFrom-Json
837+
838+
# Chose images that are validated or validating, Linux and can be used in CI.
839+
$linuxImages = $matrix.preview |
840+
Where-Object {$_.IsLinux -and $_.UseInCi -and $_.DistributionState -match 'Validat.*' -and $_.JobName -match $ContainerPattern} |
841+
Select-Object JobName, Taglist |
842+
Sort-Object -property JobName
843+
844+
# Use the selected seed to pick a container
845+
$index = Get-Random -Minimum 0 -Maximum $linuxImages.Count -SetSeed $seed
846+
$selectedImage = $linuxImages[$index]
847+
848+
# Filter to the first test-deps compatible tag
849+
$tag = $selectedImage.Taglist -split ';' | Where-Object {$_ -match 'preview-\D+'} | Select-Object -First 1
850+
851+
# Calculate the container name
852+
$containerName = "mcr.microsoft.com/powershell/test-deps:$tag"
853+
854+
Set-BuildVariable -Name containerName -Value $containerName -IsOutput
855+
Set-BuildVariable -Name containerBuildName -Value $selectedImage.JobName -IsOutput
856+
857+
if($env:BUILD_REASON -eq 'PullRequest') {
858+
Write-Host "##vso[build.updatebuildnumber]PR-${env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}-$($selectedImage.JobName)-$((get-date).ToString("yyyyMMddhhmmss"))"
859+
} else {
860+
Write-Host "##vso[build.updatebuildnumber]${env:BUILD_SOURCEBRANCHNAME}-$($selectedImage.JobName)-${env:BUILD_SOURCEVERSION}-$((get-date).ToString("yyyyMMddhhmmss"))"
861+
862+
# Cannot do this for a PR
863+
Write-Host "##vso[build.addbuildtag]$($selectedImage.JobName)"
864+
}
865+
}

0 commit comments

Comments
 (0)