-
Notifications
You must be signed in to change notification settings - Fork 867
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
Display warning when the agent is run in PowerShell Core #4778
Conversation
✅ Successfully linked to Azure Boards work item(s): |
PSModulePath
PSModulePath
and checking if the agent is run from Powershell once per job
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some feedback separately; let's discuss
PSModulePath
and checking if the agent is run from Powershell once per job
src/Agent.Sdk/Util/ParentProcessUtil/InteropParentProcessFinder.cs
Outdated
Show resolved
Hide resolved
src/Agent.Sdk/Util/ParentProcessUtil/InteropParentProcessFinder.cs
Outdated
Show resolved
Hide resolved
src/Agent.Sdk/Util/ParentProcessUtil/WindowsParentProcessUtil.cs
Outdated
Show resolved
Hide resolved
src/Agent.Sdk/Util/ParentProcessUtil/WindowsParentProcessUtil.cs
Outdated
Show resolved
Hide resolved
src/Agent.Sdk/Util/ParentProcessUtil/InteropParentProcessFinder.cs
Outdated
Show resolved
Hide resolved
src/Agent.Sdk/Util/ParentProcessUtil/InteropParentProcessFinder.cs
Outdated
Show resolved
Hide resolved
src/Agent.Sdk/Util/ParentProcessUtil/WindowsParentProcessUtil.cs
Outdated
Show resolved
Hide resolved
src/Agent.Sdk/Util/ParentProcessUtil/WindowsParentProcessUtil.cs
Outdated
Show resolved
Hide resolved
src/Agent.Sdk/Util/ParentProcessUtil/WindowsParentProcessUtil.cs
Outdated
Show resolved
Hide resolved
src/Agent.Sdk/Util/ParentProcessUtil/WindowsParentProcessUtil.cs
Outdated
Show resolved
Hide resolved
…-agent into users/levochkin/fix-psmodulepath
…/microsoft/azure-pipelines-agent into users/levochkin/fix-psmodulepath
@aleksandrlevochkin, @KonstantinTyukalov @kirill-ivlev, @merlynomsft this request is the first time in a long time I've seen an update to to PowerShell3Handler.cs. Can you kindly take a look at my pull request #4502 which also touches that file? There's a long standing bug there that I would love to see addressed. |
WI
AB#2142810
Problem
The problem typically arises when the agent is started from PowerShell Core and executes a PowerShell task (doesn't matter if the
pwsh
flag is set or not). In this case the environment variablePSModulePath
is copied from PowerShell Core to the agent to Windows PowerShell. Thus, Windows PowerShell attempts to use modules from PowerShell Core locations. This is described in more details here: PowerShell/PowerShell#18530 (comment)Solution
Added a new knob
AZP_AGENT_CHECK_PSMODULES_LOCATIONS
. When it is enabled, when the agent is started in PowerShell Core the following message is displayed in the terminal:The same message is output to the pipeline if it attempts to execute a Windows PowerShell task and the
PSModulePath
env variable contains some well-known PowerShell Core locations:Also made some changes to prevent memory problems related to finding parent processes:
AZP_AGENT_USE_INTEROP_TO_FIND_PARENT_PROCESS
knob and related codeTesting
Tested with several Powershell scripts in my test org.
Added L0 tests.