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

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

Open
JelleBroekhuijsen opened this issue Jun 5, 2020 · 14 comments

Comments

@JelleBroekhuijsen
Copy link

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):

  • OS: Windows Server 2019 1809 17763.1217
  • PowerShell Version: 5.1.17763.1007
  • cChoco 2.4.1.0
@JelleBroekhuijsen
Copy link
Author

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
Copy link
Member

pauby commented Jun 23, 2020

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
Copy link
Author

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
Copy link
Member

pauby commented Jun 23, 2020

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
Copy link
Author

  • We have resolved the issue with our package so the package which originally caused me to discover this issue is no longer causing this. However any package that fails seems to be causing this behavior so you could create any package where the chocolateyinstall.ps1 throws an error.

  • No it does not.

  • The exit code from the logging would be -1

@JelleBroekhuijsen
Copy link
Author

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
Copy link
Author

JelleBroekhuijsen commented Jul 1, 2020

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
Copy link
Contributor

ptoonen commented Jul 30, 2020

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
Copy link

djwork commented Dec 10, 2020

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
Copy link
Author

@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 added a commit to pauby/cChoco that referenced this issue Jul 16, 2021
@pauby
Copy link
Member

pauby commented Jul 16, 2021

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

@pauby pauby added this to the 2.6.0 milestone Jul 16, 2021
MattJeanes added a commit to MattJeanes/cChoco that referenced this issue May 10, 2022
@timothy-mcroy-cengage
Copy link
Contributor

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

While MattJeanes@559341c 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
Copy link
Member

pauby commented May 16, 2022

@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
Copy link
Contributor

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.

@vexx32 vexx32 modified the milestones: 2.6.0, 2.x Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants