Chocolatey - Manage Config

Octopus.Script exported 2020-08-13 by pauby belongs to ‘Chocolatey’ category.

Allows managing Chocolatey config.

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

(Required) Config Name

ChocolateyConfigName =

The config name you want to manage. This is a single config name. Multiple config names must be managed in separate steps.

Example:

  • cacheLocation
  • commandExeecutionTimeoutSeconds

(Required) Config Action

ChocolateyConfigAction = set

The action to perform on the config name.

(Required / Optional)

ChocolateyConfigValue =

The value of the config name you want to set. This is not required if the action is ‘unset’ and required if the action is ‘set’.

(Optional) Other Chocolatey Parameters

ChocolateyConfigOtherParameters =

Other parameters to pass to Chocolatey. You can pass multiple parameters separated by a space.

Examples:

  • —debug
  • —debug —verbose

Script body

Steps based on this template will execute the following PowerShell script.

[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
$chocolateyBin = [Environment]::GetEnvironmentVariable("ChocolateyInstall", "Machine") + "\bin"
if(-not (Test-Path $chocolateyBin)) {
    Write-Host "Environment variable 'ChocolateyInstall' was not found in the system variables. Attempting to find it in the user variables..."
    $chocolateyBin = [Environment]::GetEnvironmentVariable("ChocolateyInstall", "User") + "\bin"
}

$choco = "$chocolateyBin\choco.exe"

if (-not (Test-Path $choco)) {
    throw "Chocolatey was not found at $chocolateyBin."
}

# Report the actual version here
$chocoVersion = & $choco --version
Write-Host "Running Chocolatey version $chocoVersion"

# default args
$chocoArgs = @('config', $ChocolateyConfigAction, '--yes')

# we need a source name
if ([string]::IsNullOrEmpty($ChocolateyConfigName)) {
    throw "To manage a feature,  you need to provide a feature name."
}
else {
	$chocoArgs += "--name=""'$ChocolateyConfigName'"""
}

if ($ChocolateyConfigAction -eq 'set') {
    if ([string]::IsNullOrEmpty($ChocolateyConfigValue)) {
        throw 'To set the config, you need to provide a value.'
    }
    
    $chocoArgs += "--value=""'$ChocolateyConfigValue'"""
}

# finally add any other parameters
if (-not [string]::IsNullOrEmpty($ChocolateyConfigOtherParameters)) {
	$chocoArgs += $ChocolateyConfigOtherParameters -split ' '
}

# execute the command line
Write-Host "Running the command: $choco $chocoArgs"
& $choco $chocoArgs

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "dd45cba9-a39b-43e0-922e-da9fb7818186",
  "Name": "Chocolatey - Manage Config",
  "Description": "Allows managing Chocolatey config.",
  "Version": 1,
  "ExportedAt": "2020-08-13T20:03:44.800Z",
  "ActionType": "Octopus.Script",
  "Author": "pauby",
  "Packages": [],
  "Parameters": [
    {
      "Id": "3d26fd31-9a8a-432d-add8-caee77c88235",
      "Name": "ChocolateyConfigName",
      "Label": "(Required) Config Name",
      "HelpText": "The config name you want to manage. This is a single config name. Multiple config names must be managed in separate steps.\n\nExample:\n\n* _cacheLocation_\n* _commandExeecutionTimeoutSeconds_",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "5eda17f2-d5e0-4e7b-a005-f540d1854db9",
      "Name": "ChocolateyConfigAction",
      "Label": "(Required) Config Action",
      "HelpText": "The action to perform on the config name.",
      "DefaultValue": "set",
      "DisplaySettings": {
        "Octopus.ControlType": "Select",
        "Octopus.SelectOptions": "set|Set a config\nunset|Unset a config"
      }
    },
    {
      "Id": "120540e8-0915-469f-bfc7-5ab0f8dec244",
      "Name": "ChocolateyConfigValue",
      "Label": "(Required / Optional)",
      "HelpText": "The value of the config name you want  to set. This is not required if the action is 'unset' and required if the action is 'set'.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "8ecc2ac2-4566-4b98-a979-67b755971460",
      "Name": "ChocolateyConfigOtherParameters",
      "Label": "(Optional) Other Chocolatey Parameters",
      "HelpText": "Other parameters to pass to Chocolatey. You can pass multiple parameters separated by a space.\n\nExamples:\n\n* _--debug_\n* _--debug_ _--verbose_",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptBody": "[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12\n$chocolateyBin = [Environment]::GetEnvironmentVariable(\"ChocolateyInstall\", \"Machine\") + \"\\bin\"\nif(-not (Test-Path $chocolateyBin)) {\n    Write-Host \"Environment variable 'ChocolateyInstall' was not found in the system variables. Attempting to find it in the user variables...\"\n    $chocolateyBin = [Environment]::GetEnvironmentVariable(\"ChocolateyInstall\", \"User\") + \"\\bin\"\n}\n\n$choco = \"$chocolateyBin\\choco.exe\"\n\nif (-not (Test-Path $choco)) {\n    throw \"Chocolatey was not found at $chocolateyBin.\"\n}\n\n# Report the actual version here\n$chocoVersion = & $choco --version\nWrite-Host \"Running Chocolatey version $chocoVersion\"\n\n# default args\n$chocoArgs = @('config', $ChocolateyConfigAction, '--yes')\n\n# we need a source name\nif ([string]::IsNullOrEmpty($ChocolateyConfigName)) {\n    throw \"To manage a feature,  you need to provide a feature name.\"\n}\nelse {\n\t$chocoArgs += \"--name=\"\"'$ChocolateyConfigName'\"\"\"\n}\n\nif ($ChocolateyConfigAction -eq 'set') {\n    if ([string]::IsNullOrEmpty($ChocolateyConfigValue)) {\n        throw 'To set the config, you need to provide a value.'\n    }\n    \n    $chocoArgs += \"--value=\"\"'$ChocolateyConfigValue'\"\"\"\n}\n\n# finally add any other parameters\nif (-not [string]::IsNullOrEmpty($ChocolateyConfigOtherParameters)) {\n\t$chocoArgs += $ChocolateyConfigOtherParameters -split ' '\n}\n\n# execute the command line\nWrite-Host \"Running the command: $choco $chocoArgs\"\n& $choco $chocoArgs",
    "Octopus.Action.EnabledFeatures": ""
  },
  "Category": "Chocolatey",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/chocolatey-manage-config.json",
  "Website": "/step-templates/dd45cba9-a39b-43e0-922e-da9fb7818186",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAZhQTFRF////gLXjiEsuoG9YJCxcmcTpapS4cD8nuJOCoMjqlF1DrIFteqzbaZPBKjVkO05+k8DocJzDUnGgR1+PMD1tXoKwb5vKNUZ1daTSQVeGTGiXY4q5WHmodkIplWtXd0o0o3RdgkgsmmZOkVk+ga7YiFI5g5SqhmxnhmZbh1hFg42fhXNyj6/KhIeUs9PvgajMgpu2hXl9h19QhICJgqHBdEQtlGZQm2tVeUs1rYNvqXxosYl2roNwnW1WcEQwsId0mWpUm6m8onJbao+vmb/gkaK3oHRhs5SFfUw0nYF3fE44i6jGdkgygKfMkGJMiF5JbHSCnZSXcUYzqHtmdUYwa4Sdfpi0mrTOpXdhpHRec0Mrnm5XeYGRfqbMck4/noR8blpUhq/UbWpwhVdBhFZAcUEpr4ZylmxYnGlRs5WHek04lLXSjV9JfEoyfZ/An39zm3NgiLbVmZihrIp6uZaFq39qiFpEb09CnJ+qqn5pa4mmmH10nWtTilxGsYh1rtDuroRxbkk5jllAl2lTjY2VeWVfdGVka3mKgG9D1QAACAFJREFUeNrsmoV/20YUx2tLm7vmYBVZtHYQzrIkTbO2o65rx8zMzMzM//bu3juBKZUcqYnX9/t8+mliS9Z9H9/Fhw6RSCQSiUQikUgkEolEIpFIJBKJRCKRSCQSiUQikUiky0k3Gn141QHSrzcZ1QC50uho5wDp6iuMCIRACIRACIRACIRACIRACIRACIRACIRALgsQztn/AcQRtm3Hsw/i2iB31kFi24jPNgjPOMa6hEuZzgiItG2BwSVH3/T16/sIEiaOk1TjCBVHgOE1ChLqKiD2DYShgfuDFfXz8Rentp2Y+JLjvAVv7w9I4JmY96t4pA/rD/T1ztj0ifYr2Vk/S16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FkI+s2qoNUoPDev4dDfJNnfXcpkF2bm8fpA6HZZ1VIC/cWeeOW84okLes1kF2aq3K+l6BPFBvQb/MHX/75tZBdmo+4q5bj/UeqXeL8shpq22Qndqmuu3YUzXj/bnfjv/cNkh9DuuWd9+se8vZD061DLIzTeh+9mfdO75+1GoZ5MvDU+j92nd8de80zzl8iEQikUgkEolEIpFIJBKJRCKRSCQSiUQikUgkEolEIl1O+k+AAQDVNykpMZlchAAAAABJRU5ErkJggg==",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Thursday, August 13, 2020