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

cChocoPackageInstall can fail if run immediately after Chocolatey is installed. Invalid Path #174

Open
4 tasks done
rcarpenter79 opened this issue Apr 13, 2023 · 0 comments · May be fixed by #178
Open
4 tasks done
Labels

Comments

@rcarpenter79
Copy link

Checklist

  • I have verified this is the correct repository for opening this issue.
  • I have verified no other issues exist related to my problem.
  • I have verified this is not an issue for a specific package.
  • I have verified this issue is not security related.

What You Are Seeing?

When I ran this resource on a server that was freshly built I was seeing errors about invalid paths.

I looked at the code and traced the problem to the functions Get-ChocoInstalledPackage and Get-ChocoVersion.

The problem was caused by the environment variable $env:ChocolateyInstall being null.
I could retrieve the requried value using [environment]::GetEnvironmentVariable('ChocolateyInstall', 'Machine').

This problem was intermittent. I think it depended on the order that DSC ran the resources, as several steps caused the server I was building to reboot. I think a reboot after installing Chocolatey avoids this issue.

What is Expected?

The code should check if the environment variables haven't been initialised yet and update them if they haven't.

Adding this to the start of both functions resolves the problem.

if ([string]::IsNullOrEmpty($env:ChocolateyInstall))
{
    $env:ChocolateyInstall = [environment]::GetEnvironmentVariable('ChocolateyInstall', 'Machine')
}

How Did You Get This To Happen?

This problem happened when installing Chocolatey and then trying to install a package immediately afterwards.

System Details

  • Operating System: 10.0.20348.0
  • Windows PowerShell version: 5.1.20348.1366
  • Chocolatey CLI Version: 1.3.1
  • Chocolatey Licensed Extension version: N/A
  • Chocolatey License type: Community
  • Terminal/Emulator: PowerShell

Installed Packages

chocolatey 1.3.1
chocolatey-compatibility.extension 1.0.0
chocolatey-core.extension 1.4.0
notepadplusplus 8.5.2
notepadplusplus.install 8.5.2

Output Log

I don't have the error in the log file. 
I rebuilt the server using a modified local copy of the cChoco module to test my change.

Additional Context

No response

rcarpenter79 pushed a commit to rcarpenter79/cChoco that referenced this issue Jul 7, 2023
Assigns $env:ChocolateyInstall from the System environment variable if $env:ChocolateyInstal is $null (chocolatey#174)
@rcarpenter79 rcarpenter79 linked a pull request Jul 7, 2023 that will close this issue
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant