WinSW - Install

Octopus.Script exported 2020-08-03 by cryptic-ai belongs to ‘Windows’ category.

Verify that WinSW is installed, if it is not, install it.

Parameters

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

WinSW URL

winsw-url =

WinSW URL to download.

WinSW Path

winsw-path = c:\winsw\base

Location where WinSW is installed.

WinSW Auto Install

winsw-auto-install = true

Should WinSW automatically install.

WinSW Filename

winsw-filename = winsw.exe

Name of the base winsw file.

Script body

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

$winswPath = $OctopusParameters["winsw-path"]
$winswFilename = $OctopusParameters["winsw-filename"]
$winswFullPath = "$winswPath\$winswFilename"
$winswUrl = $OctopusParameters["winsw-url"]
$winswAutoInstall = $OctopusParameters["winsw-auto-install"]

Write-Host "Checking to ensure WinSW is installed."
Write-Host "For more information on WinSW check out https://github.com/winsw/winsw"

Write-Host "WinSW should be installed at $winswFullPath"
Write-Host "Checking to ensure base path is located at $winswPath"

if (-not (Test-Path -LiteralPath "$winswPath" -PathType Container)) {
	Write-Host "Path was not found. Creating the directory now."
    
    New-Item -Path "$winswPath" -ItemType Directory
    
    Write-Host "Directory created."
}


if (-not (Test-Path -LiteralPath "$winswFullPath" -PathType Leaf)) {

	Write-Host "WinSW was not found at '$winswFullPath'. Check to see if auto install flag is true."
    
    if ($winswAutoInstall -eq $true) {
    	
        Write-Host "Flag is true, installing WinSW from $winswUrl to $winswFullPath"
        
        if ($winswUrl -eq $false) {
        	
            Write-Error "WinSW download URL is not set."
            
        } else {
        	
            Invoke-WebRequest -Uri $OctopusParameters["winsw-url"] -OutFile "$winswFullPath"
        
        	Write-Host "WinSW installed at $winswPath."
        }
        
    } else {
    	
        Write-Error "Flag is false, you will need to install WinSW to $winswFullPath."
        
    }
}

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": "b50efca4-ceb6-4e40-b000-d593d7f5ff76",
  "Name": "WinSW - Install",
  "Description": "Verify that WinSW is installed, if it is not, install it.",
  "Version": 1,
  "ExportedAt": "2020-08-03T13:53:12.815Z",
  "ActionType": "Octopus.Script",
  "Author": "cryptic-ai",
  "Packages": [],
  "Parameters": [
    {
      "Id": "edd462d9-3e00-40de-8ce3-cc387938e237",
      "Name": "winsw-url",
      "Label": "WinSW URL",
      "HelpText": "WinSW URL to download.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "47ca8207-301d-41ac-96fc-e3122bdeaa21",
      "Name": "winsw-path",
      "Label": "WinSW Path",
      "HelpText": "Location where WinSW is installed.",
      "DefaultValue": "c:\\winsw\\base",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "037be70a-c8f6-479b-a62c-7d77ef7d3a94",
      "Name": "winsw-auto-install",
      "Label": "WinSW Auto Install",
      "HelpText": "Should WinSW automatically install.",
      "DefaultValue": "true",
      "DisplaySettings": {
        "Octopus.ControlType": "Checkbox"
      }
    },
    {
      "Id": "9221c0e5-e544-43a2-acb4-40f601b46115",
      "Name": "winsw-filename",
      "Label": "WinSW Filename",
      "HelpText": "Name of the base winsw file.",
      "DefaultValue": "winsw.exe",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptBody": "$winswPath = $OctopusParameters[\"winsw-path\"]\n$winswFilename = $OctopusParameters[\"winsw-filename\"]\n$winswFullPath = \"$winswPath\\$winswFilename\"\n$winswUrl = $OctopusParameters[\"winsw-url\"]\n$winswAutoInstall = $OctopusParameters[\"winsw-auto-install\"]\n\nWrite-Host \"Checking to ensure WinSW is installed.\"\nWrite-Host \"For more information on WinSW check out https://github.com/winsw/winsw\"\n\nWrite-Host \"WinSW should be installed at $winswFullPath\"\nWrite-Host \"Checking to ensure base path is located at $winswPath\"\n\nif (-not (Test-Path -LiteralPath \"$winswPath\" -PathType Container)) {\n\tWrite-Host \"Path was not found. Creating the directory now.\"\n    \n    New-Item -Path \"$winswPath\" -ItemType Directory\n    \n    Write-Host \"Directory created.\"\n}\n\n\nif (-not (Test-Path -LiteralPath \"$winswFullPath\" -PathType Leaf)) {\n\n\tWrite-Host \"WinSW was not found at '$winswFullPath'. Check to see if auto install flag is true.\"\n    \n    if ($winswAutoInstall -eq $true) {\n    \t\n        Write-Host \"Flag is true, installing WinSW from $winswUrl to $winswFullPath\"\n        \n        if ($winswUrl -eq $false) {\n        \t\n            Write-Error \"WinSW download URL is not set.\"\n            \n        } else {\n        \t\n            Invoke-WebRequest -Uri $OctopusParameters[\"winsw-url\"] -OutFile \"$winswFullPath\"\n        \n        \tWrite-Host \"WinSW installed at $winswPath.\"\n        }\n        \n    } else {\n    \t\n        Write-Error \"Flag is false, you will need to install WinSW to $winswFullPath.\"\n        \n    }\n}",
    "Octopus.Action.EnabledFeatures": ""
  },
  "Category": "Windows",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/winsw-install.json",
  "Website": "/step-templates/b50efca4-ceb6-4e40-b000-d593d7f5ff76",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////Da3qSsLvhtb0wur6O7zuWcfxldv2aMzyK7ftpOD3s+X48Pr+0fD7d9HzHLLr4fX8xD/OcwAAAaNJREFUeNrs3cFygjAUQFECWott1f//2sJoW6kIKEzNs+euXOmcmSSGDa8oJEmSJEmSJGmsj1W1K9cpsGD1Vr2WdToVEPC+2lYvZfpVrEW0qZpF1F+MRdRugzoNlvkiarfBPk0pT8GhWUSX2yASpDlLr2+DEJBmEY1ug6whx7N0n2b30G1QlmmxHsRYp6X76yvF9vg5RYQczq8UVURI35UiFmTgShED0p6lI1eKzCHTrxS5Qk6PZ9PLDtJ9PIsJmXWlyAky6/dAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQMJCyjltF/iO3gpJUpD8s4OAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgID8T8itwwKyhbTdMr4ha8hXUwZqhICcOgyNOIkE+V5wo4MSgr1u/fp7poO+AL8K/gL8yw0UeyRB34m9iQ/pVD8L5JYTO3NI58R+AsiEEzsW5OfE3sUe/zRwYkeGnG2g2CPS7rhjF4GKP0ZwyoldxK37kFqEL/7wU0mSJEmSJOmJ+xRgAHxZTCXGdZkfAAAAAElFTkSuQmCC",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Monday, August 3, 2020