Closed cribeiro84 closed 4 years ago
PR raised: #129
@cribeiro84 Is this an issue for Chocolatey that should be raised? I would have though $env:ChocolateyInstall not being populated is a bug?
Does it happen when you install Chocolatey outside of cChoco or only when cChoco installs Chocolatey?
@pauby this issue happens during the Get-ChocoInstalledPackage call. When it tries to get the cache location, for some reaosn, the $env:ChocolateyInstall is null/empty but if I open a new PowerShell window and try to get the $env:ChocolateyInstall outside of the cChoco context, it works.
@cribeiro84 Thanks for confirming that. I think we need to look at what is causing the issue (sounds like scope) rather than working around it.
Can you give me steps you go through so I can replicate it?
I'm really sorry for the delay in replying back to you @pauby. What I did was just to install the cChoco module on my server and I ran the PowerShell as Administrator directly on the server. My DSC script I added the following block:
foreach ($chocoPackage in $node.ChocoPackages) { cChocoPackageInstaller $("ChocoPackage$chocoPackage") { Ensure = 'Present' Name = $chocoPackage } }
Using your code I cannot reproduce this error. I do get a different error but if use:
cChocoInstaller InstallChoco
{
InstallDir = "$env:ALLUSERSPROFILE\Chocolatey"
}
foreach ($chocoPackage in $node.ChocoPackages) {
cChocoPackageInstaller $("ChocoPackage$chocoPackage") {
Ensure = 'Present'
Name = $chocoPackage
DependsOn = '[cChocoInstaller]installChoco'
}
}
It works. The part added is the DependsOn = '[cChocoInstaller]installChoco'
to each package declaration and the:
cChocoInstaller InstallChoco
{
InstallDir = "$env:ALLUSERSPROFILE\Chocolatey"
}
Sorry for the delay. I was not able to reproduce the issue anymore, closing this issue.
There is an unexpected behaviour that's getting the $env:ChocolateyInstall as null value.