Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSScriptAnalyzer 1.24.0 broken in CI/CD pipeline: The term 'Invoke-ScriptAnalyzer' is not recognized as a name of a cmdlet, function, script file, or executable program. #2087

Closed
ggiesen opened this issue Mar 18, 2025 · 13 comments

Comments

@ggiesen
Copy link

ggiesen commented Mar 18, 2025

Before submitting a bug report:

  • Make sure you are able to repro it on the latest released version
  • Perform a quick search for existing issues to check if this bug has already been reported

Steps to reproduce

pwsh -Command "Set-PSRepository -ErrorAction Stop -InstallationPolicy Trusted -Name PSGallery -Verbose"
pwsh -Command "Install-Module -Name PSScriptAnalyzer -Verbose"
pwsh -Command "Invoke-ScriptAnalyzer -EnableExit -Recurse -Path ."

Expected behavior

pwsh -Command "Install-Module -Name PSScriptAnalyzer -Verbose"

VERBOSE: Acquiring providers for assembly: /opt/microsoft/powershell/7/Modules/PackageManagement/coreclr/netstandard2.0/Microsoft.PackageManagement.NuGetProvider.dll

VERBOSE: Acquiring providers for assembly: /opt/microsoft/powershell/7/Modules/PackageManagement/coreclr/netstandard2.0/Microsoft.PackageManagement.ArchiverProviders.dll

VERBOSE: Acquiring providers for assembly: /opt/microsoft/powershell/7/Modules/PackageManagement/coreclr/netstandard2.0/Microsoft.PackageManagement.MetaProvider.PowerShell.dll

VERBOSE: Acquiring providers for assembly: /opt/microsoft/powershell/7/Modules/PackageManagement/coreclr/netstandard2.0/Microsoft.PackageManagement.CoreProviders.dll

VERBOSE: Using the provider 'PowerShellGet' for searching packages.

VERBOSE: The -Repository parameter was not specified.  PowerShellGet will use all of the registered repositories.

VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.

VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2' and PackageManagementProvider is 'NuGet'.

VERBOSE: Searching repository '[https://www.powershellgallery.com/api/v2/FindPackagesById()?id='PSScriptAnalyzer'](https://www.powershellgallery.com/api/v2/FindPackagesById()?id=%27PSScriptAnalyzer%27)' for ''.

VERBOSE: Total package yield:'1' for the specified package 'PSScriptAnalyzer'.

VERBOSE: Performing the operation "Install-Module" on target "Version '1.24.0' of module 'PSScriptAnalyzer'".

VERBOSE: The installation scope is specified to be 'CurrentUser'.

VERBOSE: The specified module will be installed in '/root/.local/share/powershell/Modules'.

VERBOSE: The specified Location is 'NuGet' and PackageManagementProvider is 'NuGet'.

VERBOSE: Downloading module 'PSScriptAnalyzer' with version '1.24.0' from the repository 'https://www.powershellgallery.com/api/v2'.

VERBOSE: Searching repository '[https://www.powershellgallery.com/api/v2/FindPackagesById()?id='PSScriptAnalyzer'](https://www.powershellgallery.com/api/v2/FindPackagesById()?id=%27PSScriptAnalyzer%27)' for ''.

VERBOSE: InstallPackage' - name='PSScriptAnalyzer', version='1.24.0',destination='/tmp/287248351'

VERBOSE: DownloadPackage' - name='PSScriptAnalyzer', version='1.24.0',destination='/tmp/287248351/PSScriptAnalyzer.1.24.0/PSScriptAnalyzer.1.24.0.nupkg', uri='https://www.powershellgallery.com/api/v2/package/PSScriptAnalyzer/1.24.0'

VERBOSE: Downloading 'https://www.powershellgallery.com/api/v2/package/PSScriptAnalyzer/1.24.0'.

VERBOSE: Completed downloading 'https://www.powershellgallery.com/api/v2/package/PSScriptAnalyzer/1.24.0'.

VERBOSE: Completed downloading 'PSScriptAnalyzer'.

VERBOSE: InstallPackageLocal' - name='PSScriptAnalyzer', version='1.24.0',destination='/tmp/287248351'

VERBOSE: Validating the 'PSScriptAnalyzer' module contents under '/tmp/287248351/PSScriptAnalyzer.1.24.0' path.

VERBOSE: Test-ModuleManifest successfully validated the module manifest file '/tmp/287248351/PSScriptAnalyzer.1.24.0'.

VERBOSE: Module 'PSScriptAnalyzer' was installed successfully to path '/root/.local/share/powershell/Modules/PSScriptAnalyzer/1.24.0'.

pwsh -Command "Invoke-ScriptAnalyzer -EnableExit -Recurse -Path ."

Actual behavior

pwsh -Command "Install-Module -Name PSScriptAnalyzer -Verbose"

VERBOSE: Acquiring providers for assembly: /opt/microsoft/powershell/7/Modules/PackageManagement/coreclr/netstandard2.0/Microsoft.PackageManagement.MetaProvider.PowerShell.dll

VERBOSE: Acquiring providers for assembly: /opt/microsoft/powershell/7/Modules/PackageManagement/coreclr/netstandard2.0/Microsoft.PackageManagement.ArchiverProviders.dll

VERBOSE: Acquiring providers for assembly: /opt/microsoft/powershell/7/Modules/PackageManagement/coreclr/netstandard2.0/Microsoft.PackageManagement.NuGetProvider.dll

VERBOSE: Acquiring providers for assembly: /opt/microsoft/powershell/7/Modules/PackageManagement/coreclr/netstandard2.0/Microsoft.PackageManagement.CoreProviders.dll

VERBOSE: Using the provider 'PowerShellGet' for searching packages.

VERBOSE: The -Repository parameter was not specified.  PowerShellGet will use all of the registered repositories.

VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.

VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2' and PackageManagementProvider is 'NuGet'.

VERBOSE: Searching repository '[https://www.powershellgallery.com/api/v2/FindPackagesById()?id='PSScriptAnalyzer'](https://www.powershellgallery.com/api/v2/FindPackagesById()?id=%27PSScriptAnalyzer%27)' for ''.

VERBOSE: Total package yield:'1' for the specified package 'PSScriptAnalyzer'.

VERBOSE: Performing the operation "Install-Module" on target "Version '1.24.0' of module 'PSScriptAnalyzer'".

VERBOSE: The installation scope is specified to be 'CurrentUser'.

VERBOSE: The specified module will be installed in '/root/.local/share/powershell/Modules'.

VERBOSE: The specified Location is 'NuGet' and PackageManagementProvider is 'NuGet'.

VERBOSE: Downloading module 'PSScriptAnalyzer' with version '1.24.0' from the repository 'https://www.powershellgallery.com/api/v2'.

VERBOSE: Searching repository '[https://www.powershellgallery.com/api/v2/FindPackagesById()?id='PSScriptAnalyzer'](https://www.powershellgallery.com/api/v2/FindPackagesById()?id=%27PSScriptAnalyzer%27)' for ''.

VERBOSE: InstallPackage' - name='PSScriptAnalyzer', version='1.24.0',destination='/tmp/906784297'

VERBOSE: DownloadPackage' - name='PSScriptAnalyzer', version='1.24.0',destination='/tmp/906784297/PSScriptAnalyzer.1.24.0/PSScriptAnalyzer.1.24.0.nupkg', uri='https://www.powershellgallery.com/api/v2/package/PSScriptAnalyzer/1.24.0'

VERBOSE: Downloading 'https://www.powershellgallery.com/api/v2/package/PSScriptAnalyzer/1.24.0'.

VERBOSE: Completed downloading 'https://www.powershellgallery.com/api/v2/package/PSScriptAnalyzer/1.24.0'.

VERBOSE: Completed downloading 'PSScriptAnalyzer'.

VERBOSE: InstallPackageLocal' - name='PSScriptAnalyzer', version='1.24.0',destination='/tmp/906784297'

VERBOSE: Validating the 'PSScriptAnalyzer' module contents under '/tmp/906784297/PSScriptAnalyzer.1.24.0' path.

VERBOSE: Test-ModuleManifest successfully validated the module manifest file '/tmp/906784297/PSScriptAnalyzer.1.24.0'.

VERBOSE: Module 'PSScriptAnalyzer' was installed successfully to path '/root/.local/share/powershell/Modules/PSScriptAnalyzer/1.24.0'.


pwsh -Command "Invoke-ScriptAnalyzer -EnableExit -Recurse -Path ."

Invoke-ScriptAnalyzer: The term 'Invoke-ScriptAnalyzer' is not recognized as a name of a cmdlet, function, script file, or executable program.

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *

Environment data

Using mcr.microsoft.com/powershell:latest container

@ggiesen
Copy link
Author

ggiesen commented Mar 18, 2025

Confirmed rolling back to 1.23.0 solves the isssue.

@bergmeister
Copy link
Collaborator

bergmeister commented Mar 19, 2025

@ggiesen What is your PowerShell version? The minimum PowerShell 7 version also got increased to 7.4.7, which was released on January 23. PowerShell support policy states that a new patch release must be updated to within a month to stay within support, therefore 7.4.7 was chosen as the oldest supported PowerShell 7 release.
cc @andyleejordan

@colinwebster-hc
Copy link

colinwebster-hc commented Mar 19, 2025

PSGallery still says minimum version is 5.1.

Image

I tried using 1.23.0 instead but got an error that it was looking for PowerShell version 7.4.6.500 (which is the same error I see for 1.24.0. Do you know which version of PS Script Analyzer was the last version to work for earlier versions of PowerShell?

This is the error I am getting in my pipeline when trying to run Invoke-ScriptAnalyzer:

Image

I did just try 1.22.0 as well and got the same error, but this was working a couple of weeks ago. I am starting to suspect that my error may not be related to this new version, but just in case there is a relation I wanted to post it here.

(Hopefully final edit): I realized that it must have still been seeing the newer version and so specified to import version 1.22.0 (as well as the install specifically). This now made my pipeline work.

@ggiesen
Copy link
Author

ggiesen commented Mar 20, 2025

@ggiesen What is your PowerShell version? The minimum PowerShell 7 version also got increased to 7.4.7, which was released on January 23. PowerShell support policy states that a new patch release must be updated to within a month to stay within support, therefore 7.4.7 was chosen as the oldest supported PowerShell 7 release.
cc @andyleejordan

7.4.2, which is the version in the 'latest' powershell container image in the Microsoft Artifact Registry:

https://mcr.microsoft.com/en-us/artifact/mar/powershell/about

@floh96
Copy link
Contributor

floh96 commented Mar 21, 2025

@bergmeister @andyleejordan there is no powershell 7.4.7 docker container.
Also the changelog says:

Breaking Changes
Minimum required PowerShell version raised from 3 to 5.1

Why did you include a breaking change in a minor version release?

@bergmeister
Copy link
Collaborator

PSGallery still says minimum version is 5.1.

Image

I tried using 1.23.0 instead but got an error that it was looking for PowerShell version 7.4.6.500 (which is the same error I see for 1.24.0. Do you know which version of PS Script Analyzer was the last version to work for earlier versions of PowerShell?

This is the error I am getting in my pipeline when trying to run Invoke-ScriptAnalyzer:

Image

I did just try 1.22.0 as well and got the same error, but this was working a couple of weeks ago. I am starting to suspect that my error may not be related to this new version, but just in case there is a relation I wanted to post it here.

(Hopefully final edit): I realized that it must have still been seeing the newer version and so specified to import version 1.22.0 (as well as the install specifically). This now made my pipeline work.

The minimum version overall is 5.1, which is also known as Windows PowerShell. The minimum PowerShell 7.x (used to be called Core) version is 7.4.7 by reference of the System.Management.Automation, it might allow up down to 7.4.6 but this version isn't recommended anyway as already out of support as all PowerShell 7.x version need to be on the latest patch version within a month of release

@bergmeister
Copy link
Collaborator

Then I suggest to open an issue in PowerShell because my understanding is that each nee patch version needs to be updated to within a month and therefore don't see why PSScriptAnalyzer should support them. cc @andyleejordan @StevenBucher98 @SydneyhSmith

@ggiesen What is your PowerShell version? The minimum PowerShell 7 version also got increased to 7.4.7, which was released on January 23. PowerShell support policy states that a new patch release must be updated to within a month to stay within support, therefore 7.4.7 was chosen as the oldest supported PowerShell 7 release.
cc @andyleejordan

7.4.2, which is the version in the 'latest' powershell container image in the Microsoft Artifact Registry:

https://mcr.microsoft.com/en-us/artifact/mar/powershell/about

@bergmeister
Copy link
Collaborator

If you look at past releases, most of the have breaking changes and don't remember that it was ever declared that semantic versioning is followed, hence the major version of 1 as breaking changes weren't big enough or new feature sets that different. The reason why this breaking change was made after many years of delay is that there a)is a very small subset of users affected by it and b) users can choose alternatives, such as running it on another PowerShell version by using PowerShell 7 or another machine and compatibility rules have been added to lint specifically on older PS versions

@bergmeister @andyleejordan there is no powershell 7.4.7 docker container.
Also the changelog says:

Breaking Changes
Minimum required PowerShell version raised from 3 to 5.1

Why did you include a breaking change in a minor version release?

@floh96
Copy link
Contributor

floh96 commented Mar 21, 2025

@bergmeister to clarify, PSScriptAnalyzer 1.24.0 is currently broken for all powershell docker users.
If possible, I suggest reverting the changes that increased the minimum version for powershell 7 to 7.4.7.
Look at https://github.com/PowerShell/PowerShell-Docker/issues there is nothing happening there in the last months, unfortunately.
If a revert is not possible, at least call it out in the changelog and release notes please.

@SamErde
Copy link

SamErde commented Mar 21, 2025

On a side note, your pipeline will complete faster and possibly even avoid this issue if you run all three of those commands in a single PowerShell instance (instead of running pwsh three times).

Try using this instead. (I also added NoProfile to the pwsh execution and explicitly specified the PSGallery repository to reduce noise in the verbose output.)

pwsh -NoProfile -Command { Set-PSRepository -ErrorAction Stop -InstallationPolicy Trusted -Name PSGallery -Verbose ; Install-Module -Name PSScriptAnalyzer -Repository PSGallery -Verbose ;  Invoke-ScriptAnalyzer -EnableExit -Recurse -Path . }

@bergmeister
Copy link
Collaborator

bergmeister commented Mar 24, 2025

@ggiesen @floh96 @colinwebster-hc
The .NET SDK image ships with PowerShell as well, which has the latest PowerShell version and therefore fix your issue. For PowerShell 7.4 use the 8.0 tags and for PowerShell 7.5, use the 9.0 tags: https://mcr.microsoft.com/en-us/artifact/mar/dotnet/sdk/about

@LeeTeng2001
Copy link

7 to 7.4.7

This bump is unnecessary as it also break existing pipeline... I had to pin script analyzer version at 1.23.0 for now.

@andyleejordan
Copy link
Member

Hi all, finally I could at least share with you about the Docker images being out of date.

7.4.2, which is the version in the 'latest' powershell container image in the Microsoft Artifact Registry:

Please see PowerShell/Announcements#75

And I confirmed following those instructions will yield up-to-date Docker images you can drop into your pipeline, both stable and LTS:

> docker run -it mcr.microsoft.com/dotnet/sdk:9.0 pwsh
PowerShell 7.5.0
PS /> exit

@devbox ~
> docker run -it mcr.microsoft.com/dotnet/sdk:8.0 pwsh
PowerShell 7.4.7
PS /> exit

As for updating the SDK package, my hands are a bit tied. I need to keep dependencies updated, and this being a dev tool, I can't reasonably ask for an exception not to update to our minimum supported version. I'm sorry about that!

@andyleejordan andyleejordan closed this as not planned Won't fix, can't repro, duplicate, stale Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants