0

Chocolatey v0.13.3 (Free version)

We are creating Chocolatey Packages for our Install Shield msi installers. When installing we are passing in package parameters (-params ) to configure some of the application configuration files after the installation.

powershell cmd

cinst Company.Package –Version 1.2.3 -myf -params "DBName=DB1;DBIP=123.4.5.6;DBSomethingElse=true"

All the parameters get passed in correctly and update the configuration files but chocolatey throws and error saying the 2nd param is not recolonized, which fails the installation.

ERROR: The term 'DBIP=123.4.5.6' is not recognized as the name of a cmdlet

chocolateyinstall.ps1

Install-ChocolateyInstallPackage @packageArgs
if ( $null -ne $env:chocolateyPackageParameters ) 
{
  Invoke-Expression "& $( Join-Path $toolsDir 'Configuration.ps1' ) $($env:chocolateyPackageParameters)"
}

And in the tools/Configuration.ps1 we are splitting the paramaters like so

$(ConvertFrom-StringData -StringData $env:chocolateyPackageParameters.Replace( ";", "`n" ) ) 

What am i missing?

I know there are better ways to configure a system (puppet,chef...) but this is all i have available atm

Flightdeck73
  • 303
  • 2
  • 8

1 Answers1

1

Passing Options Appropriately

First, ensure that you are passing your arguments appropriately through to Chocolatey. Both PowerShell.exe and cmd.exe handle quotes differently, so we suggest "'args here'" - https://chocolatey.org/docs/commands-reference#how-to-pass-options-switches

You can always run with --noop --debug to get an idea of how those options get passed through to the configuration without it actually running the installation. You will see that Chocolatey is very verbose in some of those areas.

Your Error

It looks like you found your error in a typo in Configuration.ps1, so that is good.

You might take a dependency on https://chocolatey.org/packages/chocolatey-core.extension (and download it to your internal package repository), so you can do:

$pp = Get-PackageParameters

https://github.com/chocolatey/chocolatey-coreteampackages/blob/master/extensions/chocolatey-core.extension/extensions/Get-PackageParameters.ps1

Recommendation For Scripts

If you are using this with scripts, it is suggested you use choco upgrade - it has the effect of installing if the package is not installed and upgrading if a newer version is available. HTH

ferventcoder
  • 11,952
  • 3
  • 57
  • 90