Task fails on self-hosted agent when PSRule and/or PSRule.Rules.Azure already installed
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 474
- Forks
- 65
- Avg merge
- 22h 25m
- Merged PRs (30d)
- 26
Description
Description of the issue
My tasks were working fine in the Azure DevOps hosted agent.
I just installed the self-hosted agent locally on Windows 11 x64. I already have PSRule 2.2.0 and PSRule.Rules.Azure 1.17.1 installed.
The self-hosted agent runs as the NETWORK SERVICE user.
It looks like it might be trying to uninstall or reinstall the modules, and it's erroring out.
Configuration
Yaml configuration of the extension.
- task: ps-rule-install@2
displayName: Install PSRule.Rules.Azure PS module
condition: and(succeeded(), eq('${{parameters.runPSRuleTests}}', true))
inputs:
module: PSRule.Rules.Azure
latest: false
prerelease: false
Expected behaviour
Expected it to work as it did in a hosted agent.
Error output
Starting: Install PSRule.Rules.Azure PS module
==============================================================================
Task : Install PSRule module
Description : Install a PowerShell module containing rules.
Version : 1.0.2207007
Author : Bernie White
Help : https://github.com/Microsoft/PSRule-pipelines/blob/main/docs/tasks.md#ps-rule-install
==============================================================================
[info] Using PreRelease: False
[info] Checking PowerShellGet
[info] Checking module: PSRule.Rules.Azure
[info] Installing module: PSRule.Rules.Azure
##[warning]The version '2.2.0' of module 'PSRule' is currently in use. Retry the operation after closing the applications.
##[warning]The version '1.17.1' of module 'PSRule.Rules.Azure' is currently in use. Retry the operation after closing the applications.
##[error]No match was found for the specified search criteria and module names 'PSRule.Rules.Azure'.
Finishing: Install PSRule.Rules.Azure PS module
Task in use and version:
- Task: ps-rule-install@2
Additional context
I tried commenting out the ps-rule-install task, as I already have the modules installed locally.
The next task, ps-rule-assert, failed in a similar manner as it too attempted to install the modules.
I next attempted to uninstall the modules from my machine to see if I could progress. I was blocked again with a similar message that they were in use.
I closed all terminals and powershell sessions and stopped VSCode (in which I have the PSRule extension installed). This seemed to allow me to uninstall the modules and run the job again.
This time I'm getting the following:
Starting: Run PSRule validation tests on Azure template files
==============================================================================
Task : PSRule analysis
Description : Run analysis with PSRule.
Version : 2.0.2207007
Author : Bernie White
Help : https://github.com/Microsoft/PSRule-pipelines/blob/main/docs/tasks.md#ps-rule-assert
==============================================================================
[info] Source 'C:\agent\_work\1\s\.ps-rule\' does not exist.
Checking PSRule
[info] Using repository: PSGallery
##[error]The 'Get-InstalledModule' command was found in the module 'PowerShellGet', but the module could not be loaded. For more information, run 'Import-Module PowerShellGet'.
Finishing: Run PSRule validation tests on Azure template file
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the ps-rule-install@2 and ps-rule-assert tasks, using docs/tasks.md for their documented behavior. Reproduce on a Windows 11 self-hosted agent with PSRule and PSRule.Rules.Azure already installed, then investigate the PowerShellGet loading and module-in-use errors. Done means the tasks work with preinstalled modules and produce a clear result without attempting an invalid reinstall.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- devops, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100