How do I pass parameters to the installer in a Chocolatey package?
Asked Answered
J

3

17

I created a package from an MSI. However, I need to pass in custom parameters.

/i SERVER='xx.yyy.com

Here are the few things I tried by reading the choco command spec, but none worked.

> choco install foo -y --params "SERVER='xx.yyy.com'"
> choco install foo -y --params "SERVER=xx.yyy.com"
> choco install foo -y --params "SERVER= xx.yyy.com"

How do I pass the install options to the installer?

Jointer answered 14/6, 2016 at 5:50 Comment(0)
G
22

If you are passing to the native installer, please use --install-arguments and not --package-parameters.

https://chocolatey.org/docs/commands-install#options-and-switches

 --ia, --installargs, --installarguments, --install-arguments=VALUE
 InstallArguments - Install Arguments to pass to the native installer in 
   the package. Defaults to unspecified.

-o, --override, --overrideargs, --overridearguments, --override-arguments
 OverrideArguments - Should install arguments be used exclusively without 
   appending to current package passed arguments? Defaults to false.

 --params, --parameters, --pkgparameters, --packageparameters, --package-parameters=VALUE
 PackageParameters - Parameters to pass to the package. Defaults to 
   unspecified.

Additionally, you may want to explore the documentation on how to pass options and switches - https://chocolatey.org/docs/commands-reference#how-to-pass-options-switches:

  • Quote Values: When you need to quote an entire argument, such as when using spaces, please use a combination of double quotes and apostrophes ("'value'"). In cmd.exe you can just use double quotes ("value") but in powershell.exe you should use backticks ( `"value`") or apostrophes ('value'). Using the combination allows for both shells to work without issue, except for when the next section applies.
  • Pass quotes in arguments: When you need to pass quoted values to to something like a native installer, you are in for a world of fun. In cmd.exe you must pass it like this: -ia "/yo=""Spaces spaces""". In PowerShell.exe, you must pass it like this: -ia '/yo=""Spaces spaces""'. No other combination will work. In PowerShell.exe if you are on version v3+, you can try --% before -ia to just pass the args through as is, which means it should not require any special workarounds.
Goudy answered 14/6, 2016 at 16:5 Comment(5)
they really should include this as one of the examples in the man pageMastiff
@Mastiff that's a good idea. I've added an enhancement request. Let me know if I'm off on what you mean - github.com/chocolatey/choco/issues/1717Goudy
This is a good explanation, but I think what most people are looking for is an example.Unifoliolate
What is the syntax format for --install-arguments? E.g. is it 'CUSTOMARGUMENT=""' or '/CUSTOMARGUMENT:""', etc., etc. Some examples would be very useful.Incurrence
@Incurrence the syntax is whatever the native installer expects. So with MSI properties, you would use CAPITAL_LETTERS="Value" NEXTPROPERTY="Value2" and so on. With other installers, they have different requirements. Installer Arguments are down to the "Installer" itself, so they vary. Note Package Parameters are different and they are more universal with Chocolatey, so that's easier to provide syntax for.Goudy
S
6

I found information on setting a value into a Choco package parameter quite hard to find!

choco install -h isn't much help.

As a simple example of setting a value for a package parameter (as opposed to an MSI parameter - which is quite different), here is a simple, workable example:

choco install python2 --package-parameters='"/InstallDir:D:\Python2"'

"/InstallDir" is documented as a package parameter for the "python2" Choco package.

Note that there are a few alias for "--package-parameters", the shortest being "--params" if you like to save typing.

Note also the use of colon, NOT "=", where the value is assigned.

If you need spaces in the value, surround the value with extra pairs of double quotes - i.e. four new characters required.

... I have asked on the Choco forums to improve the documentation.

Sheepdip answered 27/1, 2017 at 1:18 Comment(2)
"i have asked choco forums to improve documentation." haha i agree, their documentation is horrible.Udella
It's worth noting that when Chocolatey native offered package parameters, we ensured you could pass either : OR = as the key value separator for package parameters. We've hopefully made the docs better surrounding this. docs.chocolatey.org/en-us/guides/create/…Goudy
T
1

Addition: Usage of the --param argument in PowerShell variables to pass to the installer, e.g.

choco install vscode $ParVar

This does only work when you include an equal sign = after --params ... (instead of a whitespace). Most package documentations show it without equal sign! While this is not a problem for direct execution, it fails when passing the parameters via a variable.

Proof for VS Code:

Without equal sign:

Proceeding Code
  1. VS Code Chocolatey Documentation: | choco install vscode --params "/NoDesktopIcon /NoQuicklaunchIcon"
  2. Copy to variable: | $ParVar = '--params "/NoDesktopIcon /NoQuicklaunchIcon"'
    Pay attention to single and double-quotes (see other answers).
  3. Execution (-> error): | choco install vscode $ParVar
    Chocolatey params error in PowerShell

With equal sign:

Proceeding Code
2. Copy to variable: $ParVar = '--params="/NoDesktopIcon /NoQuicklaunchIcon"'
Pay attention to = sign after params
3. Execution (-> success): choco install vscode $ParVar
Successfull chocolatey installation

-> This can be used in all packages which need params arguments with double-quotes. I tested this with several packages.

I utilize this approach to build up key:value dictionaries of a lot of apps which I then batch install on new machines.

Taffrail answered 31/12, 2020 at 0:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.