Skip to content

Commit 156757c

Browse files
authored
Add container to Linux CI (PowerShell#17233)
1 parent 36fcec3 commit 156757c

File tree

11 files changed

+213
-138
lines changed

11 files changed

+213
-138
lines changed

.vsts-ci/linux.yml

Lines changed: 77 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@ variables:
4747
__SuppressAnsiEscapeSequences: 1
4848

4949
resources:
50-
- repo: self
51-
clean: true
50+
repositories:
51+
- repository: Docker
52+
type: github
53+
endpoint: PowerShell
54+
name: PowerShell/PowerShell-Docker
55+
ref: master
5256

5357
stages:
54-
- stage: BuildLinux
58+
- stage: BuildLinuxStage
5559
displayName: Build for Linux
5660
jobs:
5761
- template: templates/ci-build.yml
@@ -60,33 +64,34 @@ stages:
6064
jobName: linux_build
6165
displayName: linux Build
6266

63-
- stage: TestLinux
64-
displayName: Test for Linux
67+
- stage: TestUbuntu
68+
displayName: Test for Ubuntu
69+
dependsOn: [BuildLinuxStage]
6570
jobs:
6671
- template: templates/nix-test.yml
6772
parameters:
68-
name: Linux
73+
name: Ubuntu
6974
pool: ubuntu-20.04
7075
purpose: UnelevatedPesterTests
7176
tagSet: CI
7277

7378
- template: templates/nix-test.yml
7479
parameters:
75-
name: Linux
80+
name: Ubuntu
7681
pool: ubuntu-20.04
7782
purpose: ElevatedPesterTests
7883
tagSet: CI
7984

8085
- template: templates/nix-test.yml
8186
parameters:
82-
name: Linux
87+
name: Ubuntu
8388
pool: ubuntu-20.04
8489
purpose: UnelevatedPesterTests
8590
tagSet: Others
8691

8792
- template: templates/nix-test.yml
8893
parameters:
89-
name: Linux
94+
name: Ubuntu
9095
pool: ubuntu-20.04
9196
purpose: ElevatedPesterTests
9297
tagSet: Others
@@ -95,24 +100,72 @@ stages:
95100
parameters:
96101
pool: ubuntu-20.04
97102

103+
- stage: TestContainer
104+
displayName: Test in a container
105+
dependsOn: [BuildLinuxStage]
106+
jobs:
107+
- job: getContainerJob
108+
displayName: Choose a container
109+
pool:
110+
vmImage: ubuntu-20.04
111+
steps:
112+
- checkout: self
113+
clean: true
114+
115+
- checkout: Docker
116+
clean: true
117+
118+
- pwsh: |
119+
$matrix = ./PowerShell-Docker/build.ps1 -GenerateMatrixJson -FullJson -Channel preview | ConvertFrom-Json
120+
# Filter out containers that won't run on AzDevOps Linux host as an agent
121+
# Windows, nano server, alpine, and any ARM image
122+
$linuxImages = $matrix.preview |
123+
Where-Object {$_.osversion -notmatch 'windows|nano|alpine|arm'} |
124+
Select-Object JobName, Taglist |
125+
Sort-Object -property JobName
126+
# Force mariner for now, later we will add automated rotation by the month.
127+
$marinerImage = $linuxImages | where-object {$_.JobName -like 'mariner*'}
128+
Import-Module ./PowerShell/tools/ci.psm1
129+
$tag = $marinerImage.Taglist -split ';' | select-object -first 1
130+
$containerName = "mcr.microsoft.com/powershell/test-deps:$tag"
131+
Set-BuildVariable -Name containerName -Value $containerName -IsOutput
132+
Set-BuildVariable -Name containerBuildName -Value $marinerImage.JobName -IsOutput
133+
name: getContainerTask
134+
displayName: Get Container
135+
continueOnError: true
136+
137+
- template: templates/test/nix-container-test.yml
138+
parameters:
139+
name: container
140+
pool: ubuntu-20.04
141+
purpose: UnelevatedPesterTests
142+
tagSet: CI
143+
144+
- template: templates/test/nix-container-test.yml
145+
parameters:
146+
name: container
147+
pool: ubuntu-20.04
148+
purpose: ElevatedPesterTests
149+
tagSet: CI
150+
151+
- template: templates/test/nix-container-test.yml
152+
parameters:
153+
name: container
154+
pool: ubuntu-20.04
155+
purpose: UnelevatedPesterTests
156+
tagSet: Others
157+
158+
- template: templates/test/nix-container-test.yml
159+
parameters:
160+
name: container
161+
pool: ubuntu-20.04
162+
purpose: ElevatedPesterTests
163+
tagSet: Others
164+
98165
- stage: PackageLinux
99166
displayName: Package Linux
100-
dependsOn: ["BuildLinux"]
167+
dependsOn: ["BuildLinuxStage"]
101168
jobs:
102169
- template: linux/templates/packaging.yml
103170
parameters:
104171
pool: ubuntu-20.04
105-
106-
- stage: CodeCovTestPackage
107-
displayName: CodeCoverage and Test Packages
108-
dependsOn: [] # by specifying an empty array, this stage doesn't depend on the stage before it
109-
jobs:
110-
- job: CodeCovTestPackage
111-
displayName: CodeCoverage and Test Packages
112-
pool:
113-
vmImage: ubuntu-20.04
114-
steps:
115-
- pwsh: |
116-
Import-Module .\tools\ci.psm1
117-
New-CodeCoverageAndTestPackage
118-
displayName: CodeCoverage and Test Package

.vsts-ci/misc-analysis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ trigger:
55
branches:
66
include:
77
- master
8-
- release*
98
- feature*
109

1110
pr:
1211
branches:
1312
include:
1413
- master
15-
- release*
1614
- feature*
1715

1816
resources:

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

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,19 @@
11
parameters:
22
pool: 'macOS-latest'
3-
parentJobs: []
43
purpose: ''
54
tagSet: 'CI'
65
name: 'mac'
76

87
jobs:
98
- job: ${{ parameters.name }}_test_${{ parameters.purpose }}_${{ parameters.tagSet }}
10-
dependsOn:
11-
${{ parameters.parentJobs }}
9+
1210
pool:
1311
vmImage: ${{ parameters.pool }}
1412

1513
displayName: ${{ parameters.name }} Test - ${{ parameters.purpose }} - ${{ parameters.tagSet }}
1614

1715
steps:
18-
- pwsh: |
19-
Get-ChildItem -Path env:
20-
displayName: Capture Environment
21-
condition: succeededOrFailed()
22-
23-
- task: DownloadBuildArtifacts@0
24-
displayName: 'Download build artifacts'
25-
inputs:
26-
downloadType: specific
27-
itemPattern: |
28-
build/**/*
29-
downloadPath: '$(System.ArtifactsDirectory)'
30-
31-
- pwsh: |
32-
Get-ChildItem "$(System.ArtifactsDirectory)\*" -Recurse
33-
displayName: 'Capture Artifacts Directory'
34-
continueOnError: true
35-
36-
- pwsh: |
37-
Import-Module .\tools\ci.psm1
38-
Invoke-CIInstall -SkipUser
39-
displayName: Bootstrap
40-
41-
- task: ExtractFiles@1
42-
displayName: 'Extract Build ZIP'
43-
inputs:
44-
archiveFilePatterns: '$(System.ArtifactsDirectory)/build/build.zip'
45-
destinationFolder: '$(System.ArtifactsDirectory)/bins'
46-
47-
- bash: |
48-
find "$(System.ArtifactsDirectory)/bins" -type d -exec chmod +rwx {} \;
49-
find "$(System.ArtifactsDirectory)/bins" -type f -exec chmod +rw {} \;
50-
displayName: 'Fix permissions'
51-
continueOnError: true
52-
53-
- pwsh: |
54-
Get-ChildItem "$(System.ArtifactsDirectory)\bins\*" -Recurse -ErrorAction SilentlyContinue
55-
displayName: 'Capture Extracted Build ZIP'
56-
continueOnError: true
57-
58-
- pwsh: |
59-
Import-Module .\tools\ci.psm1
60-
Restore-PSOptions -PSOptionsPath '$(System.ArtifactsDirectory)\build\psoptions.json'
61-
$options = (Get-PSOptions)
62-
$rootPath = '$(System.ArtifactsDirectory)\bins'
63-
$originalRootPath = Split-Path -path $options.Output
64-
$path = Join-Path -path $rootPath -ChildPath (split-path -leaf -path $originalRootPath)
65-
$pwshPath = Join-Path -path $path -ChildPath 'pwsh'
66-
chmod a+x $pwshPath
67-
$options.Output = $pwshPath
68-
Set-PSOptions $options
69-
Invoke-CITest -Purpose '${{ parameters.purpose }}' -TagSet '${{ parameters.tagSet }}'
70-
displayName: Test
71-
condition: succeeded()
16+
- template: ./test/nix-test-steps.yml
17+
parameters:
18+
purpose: ${{ parameters.purpose }}
19+
tagSet: ${{ parameters.tagSet }}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
parameters:
2+
pool: 'macOS-latest'
3+
purpose: ''
4+
tagSet: 'CI'
5+
name: 'mac'
6+
7+
jobs:
8+
- job: ${{ parameters.name }}_test_${{ parameters.purpose }}_${{ parameters.tagSet }}
9+
10+
dependsOn:
11+
- getContainerJob
12+
13+
variables:
14+
getContainerJob: $[ dependencies.getContainerJob.outputs['getContainerTask.containerName'] ]
15+
__INCONTAINER: 1
16+
17+
container: $[ variables.getContainerJob ]
18+
19+
pool:
20+
vmImage: ${{ parameters.pool }}
21+
22+
displayName: ${{ parameters.name }} Test - ${{ parameters.purpose }} - ${{ parameters.tagSet }}
23+
24+
steps:
25+
- template: ./nix-test-steps.yml
26+
parameters:
27+
purpose: ${{ parameters.purpose }}
28+
tagSet: ${{ parameters.tagSet }}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
parameters:
2+
purpose: ''
3+
tagSet: 'CI'
4+
5+
steps:
6+
- pwsh: |
7+
Get-ChildItem -Path env:
8+
displayName: Capture Environment
9+
condition: succeededOrFailed()
10+
11+
- task: DownloadBuildArtifacts@0
12+
displayName: 'Download build artifacts'
13+
inputs:
14+
downloadType: specific
15+
itemPattern: |
16+
build/**/*
17+
downloadPath: '$(System.ArtifactsDirectory)'
18+
19+
- pwsh: |
20+
Get-ChildItem "$(System.ArtifactsDirectory)\*" -Recurse
21+
displayName: 'Capture Artifacts Directory'
22+
continueOnError: true
23+
24+
- pwsh: |
25+
Import-Module .\tools\ci.psm1
26+
Invoke-CIInstall -SkipUser
27+
displayName: Bootstrap
28+
29+
- task: ExtractFiles@1
30+
displayName: 'Extract Build ZIP'
31+
inputs:
32+
archiveFilePatterns: '$(System.ArtifactsDirectory)/build/build.zip'
33+
destinationFolder: '$(System.ArtifactsDirectory)/bins'
34+
35+
- bash: |
36+
find "$(System.ArtifactsDirectory)/bins" -type d -exec chmod +rwx {} \;
37+
find "$(System.ArtifactsDirectory)/bins" -type f -exec chmod +rw {} \;
38+
displayName: 'Fix permissions'
39+
continueOnError: true
40+
41+
- pwsh: |
42+
Get-ChildItem "$(System.ArtifactsDirectory)\bins\*" -Recurse -ErrorAction SilentlyContinue
43+
displayName: 'Capture Extracted Build ZIP'
44+
continueOnError: true
45+
46+
- pwsh: |
47+
Import-Module .\tools\ci.psm1
48+
Restore-PSOptions -PSOptionsPath '$(System.ArtifactsDirectory)\build\psoptions.json'
49+
$options = (Get-PSOptions)
50+
$rootPath = '$(System.ArtifactsDirectory)\bins'
51+
$originalRootPath = Split-Path -path $options.Output
52+
$path = Join-Path -path $rootPath -ChildPath (split-path -leaf -path $originalRootPath)
53+
$pwshPath = Join-Path -path $path -ChildPath 'pwsh'
54+
chmod a+x $pwshPath
55+
$options.Output = $pwshPath
56+
Set-PSOptions $options
57+
Invoke-CITest -Purpose '${{ parameters.purpose }}' -TagSet '${{ parameters.tagSet }}'
58+
displayName: Test
59+
condition: succeeded()

test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,8 @@ Describe "Test-Connection" -tags "CI", "RequireSudoOnUnix" {
9797
{ Test-Connection "fakeHost" -Count 1 -ErrorAction Stop } |
9898
Should -Throw -ErrorId "TestConnectionException,Microsoft.PowerShell.Commands.TestConnectionCommand"
9999
# Error code = 11001 - Host not found.
100-
$platform = Get-PlatformInfo
101-
if ($platform.Platform -match "raspbian" -or ( $platform.Platform -match 'ubuntu' -and $platform.Version -eq '20.04')) {
102-
$code = 11
103-
} elseif (!$IsWindows) {
104-
$code = -131073
105-
} else {
106-
$code = 11001
107-
}
108-
$error[0].Exception.InnerException.ErrorCode | Should -Be $code
100+
# Error code = -131073 - Invalid address
101+
$error[0].Exception.InnerException.ErrorCode | Should -BeIn 11, -131073, 11001
109102
}
110103

111104
It "Force IPv4 with implicit PingOptions" {

test/powershell/engine/Remoting/PSSession.Tests.ps1

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,8 @@ Describe "SkipCACheck and SkipCNCheck PSSession options are required for New-PSS
7979
It "<Name>" -TestCases $testCases {
8080
param ($scriptBlock, $expectedErrorCode)
8181

82-
$platformInfo = Get-PlatformInfo
83-
if (
84-
($platformInfo.Platform -match "alpine|raspbian") -or
85-
($platformInfo.Platform -eq "debian" -and ($platformInfo.Version -eq '10' -or $platformInfo.Version -eq '')) -or # debian 11 has empty Version ID
86-
($platformInfo.Platform -eq 'centos' -and $platformInfo.Version -eq '8') -or
87-
($platformInfo.Platform -eq 'ubuntu' -and $platformInfo.Version -eq '20.04')
88-
) {
89-
Set-ItResult -Skipped -Because "MI library not available for Alpine, Raspberry Pi, Debian 10 and 11, and CentOS 8"
82+
if ( -not (Get-WsManSupport)) {
83+
Set-ItResult -Skipped -Because "MI library not available for this platform"
9084
return
9185
}
9286

0 commit comments

Comments
 (0)