@@ -116,20 +116,41 @@ stages:
116116 clean : true
117117
118118 - pwsh : |
119+ # For PRs set the seed to the PR number so that the image is always the same
120+ $seed = $env:SYSTEM_PULLREQUEST_PULLREQUESTID
121+ if(!$seed) {
122+ # for non-PRs use the integer identifier of the build as the seed.
123+ $seed = $env:SYSTEM_BUILD_BUILDID
124+ }
125+ Write-Verbose "Seed: $seed" -Verbose
126+
127+ # Get the latest image matrix JSON for preview
119128 $matrix = ./PowerShell-Docker/build.ps1 -GenerateMatrixJson -FullJson -Channel preview | ConvertFrom-Json
129+
120130 # Filter out containers that won't run on AzDevOps Linux host as an agent
121131 # Windows, nano server, alpine, and any ARM image
122132 $linuxImages = $matrix.preview |
123133 Where-Object {$_.osversion -notmatch 'windows|nano|alpine|arm'} |
124134 Select-Object JobName, Taglist |
125135 Sort-Object -property JobName
126- # Force mariner for now, later we will add automated rotation by the month.
136+
137+ # Force mariner for now
127138 $marinerImage = $linuxImages | where-object {$_.JobName -like 'mariner*'}
128- Import-Module ./PowerShell/tools/ci.psm1
129- $tag = $marinerImage.Taglist -split ';' | select-object -first 1
139+
140+ # Use the selected seed to pick a container
141+ $index = Get-Random -Minimum 0 -Maximum $marinerImage.Count -SetSeed $seed
142+ $selectedImage = $marinerImage[$index]
143+
144+ # Filter to the first test-deps compatible tag
145+ $tag = $selectedImage.Taglist -split ';' | Where-Object {$_ -match 'preview-\D+'} | Select-Object -First 1
146+
147+ # Calculate the container name
130148 $containerName = "mcr.microsoft.com/powershell/test-deps:$tag"
149+
150+ # Set variables for later jobs to use
151+ Import-Module ./PowerShell/tools/ci.psm1
131152 Set-BuildVariable -Name containerName -Value $containerName -IsOutput
132- Set-BuildVariable -Name containerBuildName -Value $marinerImage .JobName -IsOutput
153+ Set-BuildVariable -Name containerBuildName -Value $selectedImage .JobName -IsOutput
133154 name: getContainerTask
134155 displayName: Get Container
135156 continueOnError: true
0 commit comments