chocolatey / cChoco

Community resource to manage Chocolatey
Apache License 2.0
154 stars 99 forks source link

cChoco reports compliant state however package failed to install correctly #146

Open JelleBroekhuijsen opened 4 years ago

JelleBroekhuijsen commented 4 years ago

Describe the bug When deploying a failing self-created package from an internal source (package ends up in lib-bad folder) cChoco reports a compliant state rather than a failed state.

To Reproduce Steps to reproduce the behavior:

cChocoPackageInstaller my-custom-package{
  Name = 'my-custom-package'
  Ensure = 'present'
  Version = 'my.custom.version'
  Autoupgrade = $false
  chocoParams = '--params="mycustomparams"'
  Source = $myInternalRepository
  DependsOn = '[Script]SomeScript',' [cChocoPackageInstaller]SomeOtherPackage' 
}

Expected behavior A failed installation should lead to an incompliant state warning/error.

Software (please complete the following information):

JelleBroekhuijsen commented 4 years ago

Additionally; packages with a dependsOn on the failed package will deploy while their predecessor is not in an compliant state yet. This can cause a chain effect of failed packages.

pauby commented 4 years ago

When you install the package with Chocolatey does the package show as installed? Can you provide an example (I note it's an internal package but you may be able to share some code that I can test)?

JelleBroekhuijsen commented 4 years ago

When I check with choco list --local-only the failed package does not show in the list of installed local packages. When I run choco info the command returns '0 packages found'. As far as I know this behavior is the same for any failing package. After download and attempted installation it is moved to /lib-bad and remains there.

pauby commented 4 years ago

Can you provide an example (I note it's an internal package but you may be able to share some code that I can test)?

So if you install it with cChoco (whcih you say confirms it was installed) and then run the choco list --local-only does it show up in the list?

Can you also give me the exit code that Chocolatey exits with when you try to install the package from the command line (or preferably the logs in a gist)?

JelleBroekhuijsen commented 4 years ago
JelleBroekhuijsen commented 4 years ago

Replaying the situation on my local machine does not yield the expected result. I will try to find time soon to recreate the issue on a virtual machine with non-propitiatory packages so I can provide you with better information.

JelleBroekhuijsen commented 4 years ago

I ran into the issue again, however this time because i tried to install a version that doesn't exist on the private repository. I captured the output of the Set- and Test-TargetResource for the cchocopackageinstall.psm1:

PS C:\windowssystem32> Set-TargetResource -Name <privatename> -Source <privatesource> -Version 9.6.10.2201 -Verbose
VERBOSE Start Set-TargetResource
VERBOSE Test-ChocoInstalled
VERBOSE EnvPath contains C:\Program Files\AdoptOpenJDKjre-8.0.242.08-hotspot\bin;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPo
werShellv1.0;C:\windows\System32\OpenSSH;cchocobin;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC170\Tools\Binn
VERBOSE Test-Command choco
VERBOSE choco exists
VERBOSE YES - Choco is Installed
VERBOSE Start IsPackageInstalled <privatename>
VERBOSE EnvPath contains C:\Program Files\AdoptOpenJDKjre-8.0.242.08-hotspot\bin;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPo
werShellv1.0;C:\windows\System32\OpenSSH;cchocobin;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC170\Tools\Binn
VERBOSE Finding packages -eq <privatename>
VERBOSE Found 0 matching packages
VERBOSE Performing the operation Install package from Chocolatey on target <privatename>.
VERBOSE Install command 'choco install <privatename> -y --version=9.6.10.2201 --source=<privatesource> --no-progress'
VERBOSE Package output Chocolatey v0.10.15 Business Installing the following packages <privatename> By installing you accept licenses for the packages. <privatename> 
not installed. The package was not found with the source(s) listed.  Source(s) '<privaterepo-uri>'  NOTE 
When you specify explicit sources, it overrides default sources. If the package version is a prerelease and you didn't specify `--pre`,  the package may not be found. Ver
sion was specified as '9.6.10.2201'. It is possible that version   does not exist for '<privatename>' at the source specified. Please see https://chocolatey.org/docs/tro
ubleshooting for more   assistance.  Chocolatey installed 01 packages. 1 packages failed.  See the log for details (cchocologschocolatey.log).  Failures  - <privatename> - <privatename> not installed. The package was not found with the source(s) listed.  Source(s) '<privaterepo-uri>'  NOTE When you specify explicit sources, it overrides default sources. If the package version is a prerelease and you didn't specify `--pre`,  the packag
e may not be found. Version was specified as '9.6.10.2201'. It is possible that version   does not exist for '<privatename>' at the source specified. Please see https://
chocolatey.org/docs/troubleshooting for more   assistance.
True

PS C:\windowssystem32> test-TargetResource -Name <privatename> -Source <privatesource> -Version 9.6.10.2201 -Verbose
VERBOSE Start Test-TargetResource
VERBOSE Test-ChocoInstalled
VERBOSE EnvPath contains C:\Program Files\AdoptOpenJDKjre-8.0.242.08-hotspot\bin;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPo
werShellv1.0;C:\windows\System32\OpenSSH;cchocobin;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC170\Tools\Binn
VERBOSE Test-Command choco
VERBOSE choco exists
VERBOSE YES - Choco is Installed
VERBOSE Start IsPackageInstalled <privatename>
VERBOSE EnvPath contains C:\Program Files\AdoptOpenJDKjre-8.0.242.08-hotspot\bin;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPo
werShellv1.0;C:\windows\System32\OpenSSH;cchocobin;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC170\Tools\Binn
VERBOSE Finding packages -eq <privatename>
VERBOSE Found 0 matching packages
VERBOSE Checking if <privatename> is installed and if version matches 9.6.10.2201
VERBOSE Start IsPackageInstalled <privatename>
VERBOSE EnvPath contains C:\Program Files\AdoptOpenJDKjre-8.0.242.08-hotspot\bin;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPo
werShellv1.0;C:\windows\System32\OpenSSH;cchocobin;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC170\Tools\Binn
VERBOSE Comparing version
VERBOSE Found 0 matching packages
False

PS C:\windowssystem32>     Get-ChocoInstalledPackage -Purge

True

I have obfuscated any information that refers to the details of the package name and repository.

ptoonen commented 4 years ago

I've just looked at the behavior of Chocolatey: if you perform a choco list --local-only whilst the installation is running (before failure), it will show the package as 'installed'. Is it possible the module will perform a check at that point and mark it as installed?

djwork commented 3 years ago

I have also hit this issue and it is very serious for my company as we need to sequence installation of packages for a successful server build.

@pauby This issue is marked as still waiting on customer. Below I have provided an example of the community package corretto11jdk, in the ChocoParams I have set the install path to a drive (X:) that doesn't exist on my test server. This caused the installation to fail but the not the DSC. I have also attached the relevant section of the Chocolatey Client log from my test server which includes the exit codes as you requested. Are these examples enough for this issue to move out of "Waiting on customer"?

cChocoPackageInstaller corretto11jdkPackage {
      Name = 'corretto11jdk'
      Version = '11.0.7.10'
      ChocoParams = '--install-directory="X:\Java\x64\" --install-arguments="INSTALLDIR="X:\Java\x64\" ADDLOCAL=FeatureMain,FeatureSetupEnv,FeatureSetupRegistry,FeatureSetupEnvVars"'
      Ensure = 'Present'
      # Ensure = 'Absent'
      DependsOn = '[AEMOChocolateyConfiguration]chocolateyConfiguration'
}

Chocolatey.log

JelleBroekhuijsen commented 3 years ago

@pauby I also do not know why this is 'Waiting on user'. If there's any additional information I can provide you please let me know!

pauby commented 3 years ago

I think I've found the issue here. Working on a PR and it should be in the next release.

timothy-mcroy-cengage commented 2 years ago

Giving this a small bump. This is still not working correctly..

While https://github.com/MattJeanes/cChoco/commit/559341c8e7c5dbbcc348d5b003f85ed6740e2cc5 would fix the problem as listed in the ticket, the error should still be written in the error stream, right?

This line is https://github.com/chocolatey/cChoco/blob/development/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1#L293

The problem is that using Invoke-expression will swallow the exit code as well. A workaround is documented here

https://stackoverflow.com/a/32349023

pauby commented 2 years ago

@timothy-mcroy-cengage The fix in this repository hasn't been released yet. Are you saying the fix that was merged into develop doesn't fix it? It looks the same as MattJeanes commit.

I'm a little confused 😄

timothy-mcroy-cengage commented 2 years ago

Sorry, I was saying the change(s) linked would fix the issue, but the errors aren't being written to the error stream.

I must confess that I wrote my above comment before my morning pot of coffee and could do a better job of communicating.