-
Notifications
You must be signed in to change notification settings - Fork 14
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
Switch to using PSResourceGet for module installation + add PSGallery as repository if not present #235
Comments
We added this to our workflow before running PSRule. - name: Install required PowerShell modules
continue-on-error: false
shell: pwsh
run: |
# PowerShell preferences
$ErrorActionPreference = 'Stop'
$InformationPreference = 'Continue'
# Import PSResourceGet
Write-Information -MessageData 'Import module "Microsoft.PowerShell.PSResourceGet".'
$null = Import-Module -Name 'Microsoft.PowerShell.PSResourceGet'
# Add PSGallery if not present
Write-Information -MessageData 'Add PSGallery as repository if not already present.'
if ((Get-PSRepository -WarningAction 'SilentlyContinue').'Name' -notcontains 'PSGallery') {
Write-Information -MessageData ' Was not already present, adding it now.'
Register-PSRepository -Default
}
# Install latest version of required modules
Write-Information -MessageData 'Install modules "PSRule" and "PSRule.Rules.Azure".'
$null = Install-PSResource -Name 'PSRule', 'PSRule.Rules.Azure' -Scope 'CurrentUser' -Repository 'PSGallery' -TrustRepository -SkipDependencyCheck |
Thanks for reporting the issue @o-l-a-v.
|
Public GitHub action worker. Set up job section from the run that failed:
This job runs on multiple repos once a week, have never seen that specific error before. So looks like a one off. That maybe could be guarded against by adding PSGallery if not already added as module repository. |
@o-l-a-v Thanks for the additional information. |
Is your feature request related to a problem? Please describe.
Describe the solution you'd like
PSResourceGet is the successor to PowerShellGet and PackageManagement. It's included in the GitHub workers. Use it.
Relevant code section:
ps-rule/powershell.ps1
Lines 158 to 206 in 001a0fc
As the error shows: Add PSGallery as repository if not already present. It can be done with
Register-PSRepository -Default
, ref:Maybe something like this?
Describe alternatives you've considered
Install modules in the GitHub action before running the psrule step.
Additional context
The text was updated successfully, but these errors were encountered: