Redgate - SQL Clone, Delete Image

Octopus.Script exported 2019-05-16 by alex-yates belongs to ‘Redgate’ category.

Deletes a database image with Redgate SQL Clone.

Requires SQL Clone.

Version date: 16th May 2019

Parameters

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

SQL Clone Server (required)

cloneServer =

The URL for your SQL Clone server (e.g. http://sql-clone.example.com:14145)

SQL Clone User (optional)

cloneUser =

User account to access SQL Clone. (If left blank Octopus tentacle account will be used.)

SQL Clone Password (optional)

clonePassword =

User account to access SQL Clone. (If left blank Octopus tentacle account will be used.)

Image Name (required)

imageName =

The name of your database image.

Script body

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

$ErrorActionPreference = 'Stop'

# The code for this step template is largely a copy/paste job from the
# Azure DevOps Services step template which is maintained by Redgate:
# https://github.com/red-gate/SqlCloneVSTSExtension/blob/master/DeleteImageTask/SQLCloneDeleteImageTask.ps1
# The code was copied and adapted on 16th May 2019.

Write-Verbose "cloneServer is $cloneServer"
Write-Verbose "cloneUser is $cloneUser"
Write-Verbose "clonePassword is $clonePassword"
Write-Verbose "imageName is $imageName"

# This line is broken: Import-Module "$PSScriptRoot\Modules\RedGate.SQLClone.PowerShell.dll"

if($cloneUser){
    $password = ConvertTo-SecureString -String $clonePassword -AsPlainText -Force
    $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $cloneUser,$password

}
Connect-SqlClone -ServerUrl $cloneServer -Credential $credential
Write-Output "Connected to SQL Clone server"
        
        try
        {
            $image = Get-SqlCloneImage -Name $imageName
            Write-Output "Found image"
        }
        catch
        {
            $images = Get-SqlCloneImage
            $imageNames = "`n"
            Foreach ($cImage in $images)
            {
                $imageNames += $cImage.Name + "`n"
            }
            $message = 'SQL Clone image ' + $imageName + ' does not exist, available images: ' + $imageNames
            write-error $message
            exit 1
        }
        
        Write-Output "Deleting image"
        Remove-SqlCloneImage -Image $image | Wait-SqlCloneOperation
        Write-Output "Finished deleting image"     

Write-Debug "Leaving script SQLCloneDeleteImageTask.ps1"

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": "5ba6d0f2-04f1-4b52-adbf-9cf23b12ee58",
  "Name": "Redgate - SQL Clone, Delete Image",
  "Description": "Deletes a database image with [Redgate SQL Clone](https://www.red-gate.com/products/dba/sql-clone/index).\n\nRequires SQL Clone.\n\n*Version date: 16th May 2019*",
  "Version": 1,
  "ExportedAt": "2019-05-16T11:37:47.360Z",
  "ActionType": "Octopus.Script",
  "Author": "alex-yates",
  "Packages": [],
  "Parameters": [
    {
      "Id": "8c140a4c-65a2-4341-a604-73d14775b3a0",
      "Name": "cloneServer",
      "Label": "SQL Clone Server (required)",
      "HelpText": "The URL for your SQL Clone server (e.g. http://sql-clone.example.com:14145)",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "e5ac1d04-b8a5-440e-ba69-a5d66a53abba",
      "Name": "cloneUser",
      "Label": "SQL Clone User (optional)",
      "HelpText": "User account to access SQL Clone. (If left blank Octopus tentacle account will be used.)",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "5f6288f2-57c9-4a11-91f2-b0c2e3cb9ccd",
      "Name": "clonePassword",
      "Label": "SQL Clone Password (optional)",
      "HelpText": "User account to access SQL Clone. (If left blank Octopus tentacle account will be used.)",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      }
    },
    {
      "Id": "ee5286d3-f233-410c-92ab-36743f8743e7",
      "Name": "imageName",
      "Label": "Image Name (required)",
      "HelpText": "The name of your database image.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptBody": "$ErrorActionPreference = 'Stop'\n\n# The code for this step template is largely a copy/paste job from the\n# Azure DevOps Services step template which is maintained by Redgate:\n# https://github.com/red-gate/SqlCloneVSTSExtension/blob/master/DeleteImageTask/SQLCloneDeleteImageTask.ps1\n# The code was copied and adapted on 16th May 2019.\n\nWrite-Verbose \"cloneServer is $cloneServer\"\nWrite-Verbose \"cloneUser is $cloneUser\"\nWrite-Verbose \"clonePassword is $clonePassword\"\nWrite-Verbose \"imageName is $imageName\"\n\n# This line is broken: Import-Module \"$PSScriptRoot\\Modules\\RedGate.SQLClone.PowerShell.dll\"\n\nif($cloneUser){\n    $password = ConvertTo-SecureString -String $clonePassword -AsPlainText -Force\n    $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $cloneUser,$password\n\n}\nConnect-SqlClone -ServerUrl $cloneServer -Credential $credential\nWrite-Output \"Connected to SQL Clone server\"\n        \n        try\n        {\n            $image = Get-SqlCloneImage -Name $imageName\n            Write-Output \"Found image\"\n        }\n        catch\n        {\n            $images = Get-SqlCloneImage\n            $imageNames = \"`n\"\n            Foreach ($cImage in $images)\n            {\n                $imageNames += $cImage.Name + \"`n\"\n            }\n            $message = 'SQL Clone image ' + $imageName + ' does not exist, available images: ' + $imageNames\n            write-error $message\n            exit 1\n        }\n        \n        Write-Output \"Deleting image\"\n        Remove-SqlCloneImage -Image $image | Wait-SqlCloneOperation\n        Write-Output \"Finished deleting image\"     \n\nWrite-Debug \"Leaving script SQLCloneDeleteImageTask.ps1\"\n"
  },
  "Category": "Redgate",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/redgate-sql-clone-delete-image.json",
  "Website": "/step-templates/5ba6d0f2-04f1-4b52-adbf-9cf23b12ee58",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAD9QTFRF9s3N7Z6e3U1N87+/+NjY0RIS2Tc3zgAA/O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yGbzpGEAABEAABEAABEAABEAABEAABEAABEAA5H8F8p8AAwD2WseknbBRCwAAAABJRU5ErkJggg==",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Thursday, May 16, 2019