From e7a7c545f52407128d954cde2ae9b45573001416 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Sun, 2 Feb 2020 16:19:33 +0000 Subject: [PATCH 01/35] try using multi-job yaml with different images --- .azure-pipelines-ci/ci-unix.yaml | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/.azure-pipelines-ci/ci-unix.yaml b/.azure-pipelines-ci/ci-unix.yaml index 7e6b679a5..5955adea4 100644 --- a/.azure-pipelines-ci/ci-unix.yaml +++ b/.azure-pipelines-ci/ci-unix.yaml @@ -2,11 +2,26 @@ variables: pwsh: true # Avoid expensive initialization of dotnet cli, see: https://donovanbrown.com/post/Stop-wasting-time-during-NET-Core-builds DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 -steps: -- pwsh: | - Import-Module .\tools\appveyor.psm1 - Invoke-AppveyorInstall - ./build.ps1 -Configuration 'Release' -PSVersion 6 - ./PSCompatibilityCollector/build.ps1 -Configuration 'Release' -Framework 'netstandard2.0' - displayName: 'Build' -- template: templates/test.yaml +jobs: + - job: Ubuntu1604 + pool: + vmImage: ubuntu-16.04 + steps: + - pwsh: | + Import-Module .\tools\appveyor.psm1 + Invoke-AppveyorInstall + ./build.ps1 -Configuration 'Release' -PSVersion 6 + ./PSCompatibilityCollector/build.ps1 -Configuration 'Release' -Framework 'netstandard2.0' + displayName: 'Build' + - template: templates/test.yaml + - job: Ubuntu1804 + pool: + vmImage: ubuntu-18.04 + steps: + - pwsh: | + Import-Module .\tools\appveyor.psm1 + Invoke-AppveyorInstall + ./build.ps1 -Configuration 'Release' -PSVersion 6 + ./PSCompatibilityCollector/build.ps1 -Configuration 'Release' -Framework 'netstandard2.0' + displayName: 'Build' + - template: templates/test.yaml \ No newline at end of file From 2e4c40300dd535c36b31391c744ef9e32879f8e6 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Sun, 2 Feb 2020 16:22:54 +0000 Subject: [PATCH 02/35] fix indentation --- .azure-pipelines-ci/ci-unix.yaml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.azure-pipelines-ci/ci-unix.yaml b/.azure-pipelines-ci/ci-unix.yaml index 5955adea4..cb9351561 100644 --- a/.azure-pipelines-ci/ci-unix.yaml +++ b/.azure-pipelines-ci/ci-unix.yaml @@ -15,13 +15,13 @@ jobs: displayName: 'Build' - template: templates/test.yaml - job: Ubuntu1804 - pool: - vmImage: ubuntu-18.04 - steps: - - pwsh: | - Import-Module .\tools\appveyor.psm1 - Invoke-AppveyorInstall - ./build.ps1 -Configuration 'Release' -PSVersion 6 - ./PSCompatibilityCollector/build.ps1 -Configuration 'Release' -Framework 'netstandard2.0' - displayName: 'Build' - - template: templates/test.yaml \ No newline at end of file + pool: + vmImage: ubuntu-18.04 + steps: + - pwsh: | + Import-Module .\tools\appveyor.psm1 + Invoke-AppveyorInstall + ./build.ps1 -Configuration 'Release' -PSVersion 6 + ./PSCompatibilityCollector/build.ps1 -Configuration 'Release' -Framework 'netstandard2.0' + displayName: 'Build' + - template: templates/test.yaml \ No newline at end of file From e669e48247d41e00f661f291ff52a193f1647c8f Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Sun, 2 Feb 2020 16:35:08 +0000 Subject: [PATCH 03/35] add vm images to windows build and templatify unix build. Images now are latest ubuntu image --- .azure-pipelines-ci/ci-unix.yaml | 24 ++++++------------------ .azure-pipelines-ci/ci-windows-ps5.yaml | 2 ++ .azure-pipelines-ci/ci-windows.yaml | 2 ++ .azure-pipelines-ci/templates/unix.yaml | 8 ++++++++ 4 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 .azure-pipelines-ci/templates/unix.yaml diff --git a/.azure-pipelines-ci/ci-unix.yaml b/.azure-pipelines-ci/ci-unix.yaml index cb9351561..951b3e9f7 100644 --- a/.azure-pipelines-ci/ci-unix.yaml +++ b/.azure-pipelines-ci/ci-unix.yaml @@ -3,25 +3,13 @@ variables: # Avoid expensive initialization of dotnet cli, see: https://donovanbrown.com/post/Stop-wasting-time-during-NET-Core-builds DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 jobs: - - job: Ubuntu1604 + - job: Ubuntu pool: - vmImage: ubuntu-16.04 + vmImage: ubuntu-latest steps: - - pwsh: | - Import-Module .\tools\appveyor.psm1 - Invoke-AppveyorInstall - ./build.ps1 -Configuration 'Release' -PSVersion 6 - ./PSCompatibilityCollector/build.ps1 -Configuration 'Release' -Framework 'netstandard2.0' - displayName: 'Build' - - template: templates/test.yaml - - job: Ubuntu1804 + - template: templates/unix.yaml + - job: macOS pool: - vmImage: ubuntu-18.04 + vmImage: macos-latest steps: - - pwsh: | - Import-Module .\tools\appveyor.psm1 - Invoke-AppveyorInstall - ./build.ps1 -Configuration 'Release' -PSVersion 6 - ./PSCompatibilityCollector/build.ps1 -Configuration 'Release' -Framework 'netstandard2.0' - displayName: 'Build' - - template: templates/test.yaml \ No newline at end of file + - template: templates/unix.yaml \ No newline at end of file diff --git a/.azure-pipelines-ci/ci-windows-ps5.yaml b/.azure-pipelines-ci/ci-windows-ps5.yaml index 20648130b..876d55974 100644 --- a/.azure-pipelines-ci/ci-windows-ps5.yaml +++ b/.azure-pipelines-ci/ci-windows-ps5.yaml @@ -1,3 +1,5 @@ +pool: + vmImage: windows-latest variables: pwsh: false # Avoid expensive initialization of dotnet cli, see: https://donovanbrown.com/post/Stop-wasting-time-during-NET-Core-builds diff --git a/.azure-pipelines-ci/ci-windows.yaml b/.azure-pipelines-ci/ci-windows.yaml index f394f86c2..88316c3c3 100644 --- a/.azure-pipelines-ci/ci-windows.yaml +++ b/.azure-pipelines-ci/ci-windows.yaml @@ -1,3 +1,5 @@ +pool: + vmImage: windows-latest variables: pwsh: true # Avoid expensive initialization of dotnet cli, see: https://donovanbrown.com/post/Stop-wasting-time-during-NET-Core-builds diff --git a/.azure-pipelines-ci/templates/unix.yaml b/.azure-pipelines-ci/templates/unix.yaml new file mode 100644 index 000000000..7b85abe32 --- /dev/null +++ b/.azure-pipelines-ci/templates/unix.yaml @@ -0,0 +1,8 @@ +steps: +- pwsh: | + Import-Module .\tools\appveyor.psm1 + Invoke-AppveyorInstall + ./build.ps1 -Configuration 'Release' -PSVersion 6 + ./PSCompatibilityCollector/build.ps1 -Configuration 'Release' -Framework 'netstandard2.0' + displayName: 'Build' +- template: templates/test.yaml \ No newline at end of file From ca51510622a370af3f257f3c55083271902680b9 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Sun, 2 Feb 2020 18:24:38 +0000 Subject: [PATCH 04/35] trigger From ac4894c8e09222728b892e9d459381bd112467d5 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Sun, 2 Feb 2020 18:27:46 +0000 Subject: [PATCH 05/35] fix yaml path --- .azure-pipelines-ci/templates/unix.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure-pipelines-ci/templates/unix.yaml b/.azure-pipelines-ci/templates/unix.yaml index 7b85abe32..6d4ba43b9 100644 --- a/.azure-pipelines-ci/templates/unix.yaml +++ b/.azure-pipelines-ci/templates/unix.yaml @@ -5,4 +5,4 @@ steps: ./build.ps1 -Configuration 'Release' -PSVersion 6 ./PSCompatibilityCollector/build.ps1 -Configuration 'Release' -Framework 'netstandard2.0' displayName: 'Build' -- template: templates/test.yaml \ No newline at end of file +- template: test.yaml \ No newline at end of file From d2188be62f2db6a55b9c366fe4cd113671e6d4fd Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Sun, 2 Feb 2020 18:54:01 +0000 Subject: [PATCH 06/35] disable sporadic tests generally and add both Ubuntu images to the tests --- .azure-pipelines-ci/ci-unix.yaml | 9 ++++- Tests/Rules/UseCompatibleCommands.Tests.ps1 | 45 ++++++++++++--------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/.azure-pipelines-ci/ci-unix.yaml b/.azure-pipelines-ci/ci-unix.yaml index 951b3e9f7..7341eed9a 100644 --- a/.azure-pipelines-ci/ci-unix.yaml +++ b/.azure-pipelines-ci/ci-unix.yaml @@ -3,9 +3,14 @@ variables: # Avoid expensive initialization of dotnet cli, see: https://donovanbrown.com/post/Stop-wasting-time-during-NET-Core-builds DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 jobs: - - job: Ubuntu + - job: Ubuntu 16.04 pool: - vmImage: ubuntu-latest + vmImage: ubuntu-16.04 + steps: + - template: templates/unix.yaml + - job: Ubuntu 18.04 + pool: + vmImage: ubuntu-18.04 steps: - template: templates/unix.yaml - job: macOS diff --git a/Tests/Rules/UseCompatibleCommands.Tests.ps1 b/Tests/Rules/UseCompatibleCommands.Tests.ps1 index 6e937670c..fa6628792 100644 --- a/Tests/Rules/UseCompatibleCommands.Tests.ps1 +++ b/Tests/Rules/UseCompatibleCommands.Tests.ps1 @@ -1,6 +1,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +$script:RunningInCIOnUbuntu = $IsLinux -and ($env:TF_BUILD -or $env:APPVEYOR) # some test cases randomly start and stop to fail in Ubuntu CI tests $script:RuleName = 'PSUseCompatibleCommands' $script:AnyProfileConfigKey = 'AnyProfilePath' $script:TargetProfileConfigKey = 'TargetProfiles' @@ -23,6 +24,7 @@ $script:CompatibilityTestCases = @( @{ Target = $script:Srv2012_3_profile; Script = '"Hello World" | ConvertFrom-String | Get-Member'; Commands = @("ConvertFrom-String"); Version = "3.0"; OS = "Windows"; ProblemCount = 1 } @{ Target = $script:Srv2012_3_profile; Script = 'Compress-Archive -LiteralPath C:\Reference\Draftdoc.docx, C:\Reference\Images\diagram2.vsd -CompressionLevel Optimal -DestinationPath C:\Archives\Draft.Zip'; Commands = @("Compress-Archive"); Version = "3.0"; OS = "Windows"; ProblemCount = 1 } @{ Target = $script:Srv2012_3_profile; Script = 'Get-Runspace -Id 2'; Commands = @("Get-Runspace"); Version = "3.0"; OS = "Windows"; ProblemCount = 1 } + @{ Target = $script:Srv2012_3_profile; Script = '$Protected = "Hello World" | Protect-CmsMessage -To "*youralias@emailaddress.com*"'; Commands = @("Protect-CmsMessage"); Version = "3.0"; OS = "Windows"; ProblemCount = 1 } @{ Target = $script:Srv2012_3_profile; Script = 'Format-Hex -Path "C:\temp\temp.t7f"'; Commands = @("Format-Hex"); Version = "3.0"; OS = "Windows"; ProblemCount = 1 } @{ Target = $script:Srv2012_3_profile; Script = 'Set-Clipboard -Value "This is a test string"'; Commands = @("Set-Clipboard"); Version = "3.0"; OS = "Windows"; ProblemCount = 1 } @{ Target = $script:Srv2012_3_profile; Script = 'Clear-RecycleBin -Force'; Commands = @("Clear-RecycleBin"); Version = "3.0"; OS = "Windows"; ProblemCount = 1 } @@ -62,7 +64,6 @@ $script:CompatibilityTestCases = @( @{ Target = $script:Srv2019_5_profile; Script = 'gci .'; Commands = @(); Version = "5.1"; OS = "Windows"; ProblemCount = 0 } @{ Target = $script:Srv2019_5_profile; Script = 'iex $expr | % { Transform $_ }'; Commands = @(); Version = "5.1"; OS = "Windows"; ProblemCount = 0 } @{ Target = $script:Srv2019_5_profile; Script = 'fhx $filePath'; Commands = @(); Version = "5.1"; OS = "Windows"; ProblemCount = 0 } - @{ Target = $script:Srv2019_6_1_profile; Script = "Add-PSSnapIn MySnapIn"; Commands = @("Add-PSSnapIn"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } @{ Target = $script:Srv2019_6_1_profile; Script = "Get-PSSnapIn MySnapIn"; Commands = @("Get-PSSnapIn"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } @{ Target = $script:Srv2019_6_1_profile; Script = "Get-Content $pshome\about_signing.help.txt | Out-Printer"; Commands = @("Out-Printer"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } @@ -78,6 +79,23 @@ $script:CompatibilityTestCases = @( @{ Target = $script:Srv2019_6_1_profile; Script = 'Get-ChildItem ./ | Format-List'; Commands = @(); Version = "3.0"; OS = "Windows"; ProblemCount = 0 } @{ Target = $script:Srv2019_6_1_profile; Script = 'gci .'; Commands = @(); Version = "6.1"; OS = "Windows"; ProblemCount = 0 } @{ Target = $script:Srv2016_6_1_profile; Script = 'iex $expr | % { Transform $_ }'; Commands = @(); Version = "6.1"; OS = "Windows"; ProblemCount = 0 } + @{ Target = $script:Srv2019_6_1_profile; Script = 'ConvertFrom-String $str'; Commands = @("ConvertFrom-String"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } + @{ Target = $script:Srv2019_6_1_profile; Script = "Get-WmiObject -Class Win32_Process"; Commands = @("Get-WmiObject"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } + @{ Target = $script:Srv2019_6_1_profile; Script = "Invoke-WmiMethod -Path win32_process -Name create -ArgumentList notepad.exe"; Commands = @("Invoke-WmiMethod"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } + @{ Target = $script:Srv2019_6_1_profile; Script = '$np | Remove-WmiObject'; Commands = @("Remove-WmiObject"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } + @{ Target = $script:Srv2019_6_1_profile; Script = 'Set-Clipboard -Value "This is a test string"'; Commands = @("Set-Clipboard"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } + @{ Target = $script:Srv2019_6_1_profile; Script = "Set-WmiInstance -Class Win32_WMISetting -Argument @{LoggingLevel=2}"; Commands = @("Set-WmiInstance"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } + @{ Target = $script:Srv2019_6_1_profile; Script = 'Add-Computer -DomainName "Domain01" -Restart'; Commands = @("Add-Computer"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } + @{ Target = $script:Srv2019_6_1_profile; Script = 'Checkpoint-Computer -Description "Install MyApp"'; Commands = @("Checkpoint-Computer"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } + @{ Target = $script:Srv2019_6_1_profile; Script = 'Clear-EventLog "Windows PowerShell"'; Commands = @("Clear-EventLog"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } + @{ Target = $script:Srv2019_6_1_profile; Script = 'Clear-RecycleBin'; Commands = @("Clear-RecycleBin"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } + @{ Target = $script:Srv2019_6_1_profile; Script = 'Start-Transaction; New-Item MyCompany -UseTransaction; Complete-Transaction'; Commands = @("Start-Transaction", "Complete-Transaction"); Version = "6.1"; OS = "Windows"; ProblemCount = 2 } + @{ Target = $script:Srv2019_6_1_profile; Script = 'Disable-ComputerRestore -Drive "C:\"'; Commands = @("Disable-ComputerRestore"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } + @{ Target = $script:Srv2019_6_1_profile; Script = 'Enable-ComputerRestore -Drive "C:\", "D:\"'; Commands = @("Enable-ComputerRestore"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } + @{ Target = $script:Srv2019_6_1_profile; Script = 'Get-ControlPanelItem -Name "*Program*", "*App*"'; Commands = @("Get-ControlPanelItem"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } + @{ Target = $script:Srv2019_6_1_profile; Script = 'Get-EventLog -Newest 5 -LogName "Application"'; Commands = @("Get-EventLog"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } + @{ Target = $script:Srv2019_6_1_profile; Script = 'Get-HotFix -Description "Security*" -ComputerName "Server01", "Server02" -Cred "Server01\admin01"'; Commands = @("Get-HotFix"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } + @{ Target = $script:Srv2019_6_1_profile; Script = '$zip = New-WebServiceProxy -Uri "http://www.webservicex.net/uszip.asmx?WSDL"'; Commands = @("New-WebServiceProxy"); Version = "6.1"; OS = "Windows"; ProblemCount = 1 } @{ Target = $script:Ubuntu1804_6_1_profile; Script = 'Get-AuthenticodeSignature ./script.ps1'; Commands = @("Get-AuthenticodeSignature"); Version = "6.1"; OS = "Linux"; ProblemCount = 1 } @{ Target = $script:Ubuntu1804_6_1_profile; Script = 'Get-Service systemd'; Commands = @("Get-Service"); Version = "6.1"; OS = "Linux"; ProblemCount = 1 } @@ -120,6 +138,9 @@ $script:ParameterCompatibilityTestCases = @( @{ Target = $script:Srv2012_3_profile; Script = 'Get-Command -ShowCommandInfo'; Commands = @('Get-Command'); Parameters = @('ShowCommandInfo'); Version = '3.0'; OS = 'Windows'; ProblemCount = 1 } @{ Target = $script:Srv2012_3_profile; Script = 'Import-Module -FullyQualifiedName @{ ModuleName = "PSScriptAnalyzer"; ModuleVersion = "1.17" }'; Commands = @('Import-Module'); Parameters = @('FullyQualifiedName'); Version = '3.0'; OS = 'Windows'; ProblemCount = 1 } @{ Target = $script:Srv2012_3_profile; Script = 'Remove-Module -FullyQualifiedName @{ ModuleName = "PSScriptAnalyzer"; ModuleVersion = "1.17" }'; Commands = @('Remove-Module'); Parameters = @('FullyQualifiedName'); Version = '3.0'; OS = 'Windows'; ProblemCount = 1 } + @{ Target = $script:Srv2012_3_profile; Script = 'Register-ScheduledJob -RunNow -Trigger $t'; Commands = @('Register-ScheduledJob'); Parameters = @('RunNow'); Version = '3.0'; OS = 'Windows'; ProblemCount = 1 } + @{ Target = $script:Srv2012_3_profile; Script = 'New-JobTrigger -At "1/20/2012 3:00 AM" -RepeatIndefinitely'; Commands = @('New-JobTrigger'); Parameters = @('RepeatIndefinitely'); Version = '3.0'; OS = 'Windows'; ProblemCount = 1 } + @{ Target = $script:Srv2012_3_profile; Script = '$t = Get-ScheduledJob | Get-JobTrigger | Enable-JobTrigger -PassThru'; Commands = @('Enable-JobTrigger'); Parameters = @('PassThru'); Version = '3.0'; OS = 'Windows'; ProblemCount = 1 } @{ Target = $script:Srv2012_3_profile; Script = 'Save-Help -FullyQualifiedModule @{ ModuleName = "MyModule"; MaximumVersion = "2.7" }'; Commands = @('Save-Help'); Parameters = @('FullyQualifiedModule'); Version = '3.0'; OS = 'Windows'; ProblemCount = 1 } @{ Target = $script:Srv2012_3_profile; Script = 'Export-PSSession -FullyQualifiedModule @{ ModuleName = "MyModule"; RequiredVersion = $reqVer }'; Commands = @('Export-PSSession'); Parameters = @('FullyQualifiedModule'); Version = '3.0'; OS = 'Windows'; ProblemCount = 1 } @{ Target = $script:Srv2012_3_profile; Script = 'Get-Command -FullyQualifiedModule @{ ModuleName = $m; MaximumVersion = $maxVer }'; Commands = @('Get-Command'); Parameters = @('FullyQualifiedModule'); Version = '3.0'; OS = 'Windows'; ProblemCount = 1 } @@ -155,23 +176,9 @@ $script:ParameterCompatibilityTestCases = @( @{ Target = $script:Srv2019_6_1_profile; Script = 'Start-Service "eventlog" -ComputerName "MyComputer"'; Commands = @('Start-Service'); Parameters = @('ComputerName'); Version = '6.1'; OS = 'Windows'; ProblemCount = 1 } ) -# Disabled on AppVeyor's Ubuntu image until fixed -if (-not $IsLinux -and $env:APPVEYOR) { - $script:CompatibilityTestCases += @( - @{ Target = $script:Srv2012_3_profile; Script = '$Protected = "Hello World" | Protect-CmsMessage -To "*youralias@emailaddress.com*"'; Commands = @("Protect-CmsMessage"); Version = "3.0"; OS = "Windows"; ProblemCount = 1 } - ) - - $script:ParameterCompatibilityTestCases += @( - @{ Target = $script:Srv2012_3_profile; Script = 'Register-ScheduledJob -RunNow -Trigger $t'; Commands = @('Register-ScheduledJob'); Parameters = @('RunNow'); Version = '3.0'; OS = 'Windows'; ProblemCount = 1 } - @{ Target = $script:Srv2012_3_profile; Script = 'New-JobTrigger -At "1/20/2012 3:00 AM" -RepeatIndefinitely'; Commands = @('New-JobTrigger'); Parameters = @('RepeatIndefinitely'); Version = '3.0'; OS = 'Windows'; ProblemCount = 1 } - @{ Target = $script:Srv2012_3_profile; Script = '$t = Get-ScheduledJob | Get-JobTrigger | Enable-JobTrigger -PassThru'; Commands = @('Enable-JobTrigger'); Parameters = @('PassThru'); Version = '3.0'; OS = 'Windows'; ProblemCount = 1 } - ) -} - - Describe 'UseCompatibleCommands' { Context 'Targeting a single profile' { - It "Reports command incompatibilties with '