Chocolatey - Manage Features

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

Allows enabling and disabling of Chocolatey features.

Parameters

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

(Required) Feature Name

ChocolateyFeatureName =

The feature name to manage. Multiple feature can be specified separated by a space.

Examples:

  • checksumFiles
  • autoUninstaller allowGlobalConfirmation

(Required) Feature Action

ChocolateyFeatureAction = enable

The action to perform on the feature name.

(Optional) Other Chocolatey Parameters

ChocolateyFeatureOtherParameters =

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 = @('feature', $ChocolateyFeatureAction, '--yes')

# we need a source name
if ([string]::IsNullOrEmpty($ChocolateyFeatureName)) {
    throw "To manage a feature,  you need to provide a feature name."
}

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

$featureNames = $ChocolateyFeatureName -split ' '
ForEach ($name in $featureNames) {
	$cmdArgs = $chocoArgs + "--name=""'$name'"""

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

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": "718f6e95-e176-4f13-9512-a3a8f1bb10a0",
  "Name": "Chocolatey - Manage Features",
  "Description": "Allows enabling and disabling of Chocolatey features.",
  "Version": 1,
  "ExportedAt": "2020-08-13T17:03:20.000Z",
  "ActionType": "Octopus.Script",
  "Author": "pauby",
  "Packages": [],
  "Parameters": [
    {
      "Id": "b0258989-3337-4e22-ab96-ba54e1a533f7",
      "Name": "ChocolateyFeatureName",
      "Label": "(Required) Feature Name",
      "HelpText": "The feature name to manage. Multiple feature can be specified separated by a space. \n\nExamples:\n\n* _checksumFiles_\n* _autoUninstaller_ _allowGlobalConfirmation_",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "31522ad7-f257-4deb-9973-7d4c7eb4fa16",
      "Name": "ChocolateyFeatureAction",
      "Label": "(Required) Feature Action",
      "HelpText": "The action to perform on the feature name.",
      "DefaultValue": "enable",
      "DisplaySettings": {
        "Octopus.ControlType": "Select",
        "Octopus.SelectOptions": "enable|Enable the feature\ndisable|Disable the feature"
      }
    },
    {
      "Id": "218c539e-fe74-408a-9b6d-0b8654ae82dd",
      "Name": "ChocolateyFeatureOtherParameters",
      "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 = @('feature', $ChocolateyFeatureAction, '--yes')\n\n# we need a source name\nif ([string]::IsNullOrEmpty($ChocolateyFeatureName)) {\n    throw \"To manage a feature,  you need to provide a feature name.\"\n}\n\n# finally add any other parameters\nif (-not [string]::IsNullOrEmpty($ChocolateyFeatureOtherParameters)) {\n\t$chocoArgs += $ChocolateyFeatureOtherParameters -split ' '\n}\n\n$featureNames = $ChocolateyFeatureName -split ' '\nForEach ($name in $featureNames) {\n\t$cmdArgs = $chocoArgs + \"--name=\"\"'$name'\"\"\"\n\n    # execute the command line\n    Write-Host \"Running the command: $choco $cmdArgs\"\n    & $choco $cmdArgs\n}",
    "Octopus.Action.EnabledFeatures": ""
  },
  "Category": "Chocolatey",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/chocolatey-manage-features.json",
  "Website": "/step-templates/718f6e95-e176-4f13-9512-a3a8f1bb10a0",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAZhQTFRF////gLXjiEsuoG9YJCxcmcTpapS4cD8nuJOCoMjqlF1DrIFteqzbaZPBKjVkO05+k8DocJzDUnGgR1+PMD1tXoKwb5vKNUZ1daTSQVeGTGiXY4q5WHmodkIplWtXd0o0o3RdgkgsmmZOkVk+ga7YiFI5g5SqhmxnhmZbh1hFg42fhXNyj6/KhIe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p9fcH+TKkrzxk8bSc4rOBakZuGGnCXE5HFRx0MKRqT/OYLzTqMI0UmOW2tRL6TpJ2M7ZLxvD4XQuuRoYUUazMZrNr3CEE2a62fsuSnoAOJrZ6rq71PfZ+nZQ8eexPQwjB+JrTszp4yEV68w2CH3xbF9Bzv9fQL794QCDnKsB0rvj37ogr9/91yeXAuTC41YdkF7vjTogi1v3z80d673y0sNtgzz7qVUTpPfa+WogG+tL3W73Wg3S6123vDo/esn82omTU6x8fnN+GOQ7y6oN0vv96YuDLK6tdEEZiPpxbXHook19zdZ8XY7FhW53ZXl7cSMHufCqNQ1I747Hjl7cFd0REPX4rZID5rfwipXNeu4oPnxheWtVfeDV5+6xpgPp9f5ZnRQSm1snumUNgCidWDceOLmSX7M00Smbq9vzo+4Y1PKPljU1yDXKHEvbw6acX10becwwiF73qrp2u3zRwuoIwsvPbC+BSZYmuKPQ9XsDQWtsLWYWO7l+YsxDxoGoha8NX7u8Uaz2wbu/+PuJ/BHdteKd9YVuSyAQ42vrm3luVwMZo4VtnV2Lyg03zM3NHS8/InPXxvL4W5sC2V1VQXQhwv9HQLqLu7jjAIJkGgVZODnZHTMF0l3YmOiO2QLZXQRCIARCIARCIARCIKj7jlTVkwjyR+UbjryHIB9XvuGn6UFOn7Kq6gyAPPRi5Rusu24FkI+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