Octopus.Script exported 2015-11-26 by timhunt303 belongs to ‘RavenDB’ category.
Used to delete a file system from a server, with a possibility to remove its all data from the hard drive.
Parameters
When steps based on the template are included in a project’s deployment process, the parameters below can be set.
URL of the Raven Database
ravenFileSystemURL = http://localhost:8080/
The URL of the Raven File System, where the File System is located.
For example: http://localhost:8080/
Name of the File System
ravenFileSystemName
Name of the File System in Raven
Hard Delete
hardDelete = True
Should all of the data be removed from the hard drive as well
Allow Deletion
allowDelete
Is the File System allowed to be deleted. TRUE OR FALSE value must be entered
For example: you don’t want a production server to be deleted, the script will stop it from happening
HINT: have a variable within Octopus that returns true if it is allowed to be deleted and vice versa.
Script body
Steps based on this template will execute the following PowerShell script.
#--------------------------------------------------------------------
#Octopus Variables
#URL of RavenFS that is being deleted
$ravenFileSystemURL = $OctopusParameters["ravenFileSystemURL"]
#name of the RavenFS that is being deleted
$ravenFileSystemName = $OctopusParameters["ravenFileSystemName"]
#hard delete (true or false)
$hardDelete = $OctopusParameters["hardDelete"]
#Allow File System to be deleted
$allowDelete = $OctopusParameters["allowDelete"]
Write-Output "`n-------------------------`n"
#--------------------------------------------------------------------
#checks to see if the File System can be deleted
if($allowDelete -eq $FALSE)
{
Write-Error "$ravenFileSystemName cannot be deleted. Please try this on a database that can be delete." -ErrorId E4
Exit 1
}
#--------------------------------------------------------------------
#checks to see if the entered file system exists, return a Boolean value depending on the outcome
function doesRavenFSExist([string] $FSChecking, [string]$URL)
{
#retrieves the list of File Systems at the specified URL
$fs_list = Invoke-RestMethod -Uri "$URL/fs" -Method Get
#checks if the File System is at the specified URL
if ($fs_list -contains $FSChecking.ToString())
{
return $TRUE
}
else
{
return $FALSE
}
}#ends does File System exist function
Write-Output "`n-------------------------`n"
#--------------------------------------------------------------------
#check to see if File System exists
Write-Output "Checking if $ravenFileSystemName exists"
$fs_exists = doesRavenFSExist -FSChecking $ravenFileSystemName -URL $ravenFileSystemURL
if($fs_exists -eq $TRUE)
{
Write-Output "$ravenFileSystemName exists"
$doWork = $TRUE
}
else
{
Write-Warning "$ravenFileSystemName doesn't exist already."
$doWork = $FALSE
}
#--------------------------------------------------------------------
#converts hard delete option to a string
$hardDeleteString = $hardDelete.ToString().ToLower()
#--------------------------------------------------------------------
#Delete File System
if($doWork -eq $TRUE)
{
Write-Output "Deleting File System: $ravenFileSystemName"
$deleteURI = "$ravenFileSystemURL/admin/fs/$ravenFileSystemName" + "?hard-delete=$hardDeleteString"
Invoke-RestMethod -Uri $deleteURI -Method Delete
#Waits 10 seconds before it continues
Start-Sleep -Seconds 10
Write-Output "File System has successfuly been deleted"
}
Provided under the Apache License version 2.0.
To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.
{
"Id": "365ae5c6-8f97-4e99-82c8-9973b9b0d8ff",
"Name": "RavenDB - Delete File System",
"Description": "Used to delete a file system from a server, with a possibility to remove its all data from the hard drive.",
"Version": 5,
"ExportedAt": "2015-11-26T03:55:48.036+00:00",
"ActionType": "Octopus.Script",
"Author": "timhunt303",
"Parameters": [
{
"Name": "ravenFileSystemURL",
"Label": "URL of the Raven Database",
"HelpText": "The URL of the Raven File System, where the File System is located.\n\nFor example: **http://localhost:8080/**",
"DefaultValue": "http://localhost:8080/",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "ravenFileSystemName",
"Label": "Name of the File System",
"HelpText": "Name of the File System in Raven",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "hardDelete",
"Label": "Hard Delete",
"HelpText": "Should all of the data be removed from the hard drive as well",
"DefaultValue": "True",
"DisplaySettings": {
"Octopus.ControlType": "Checkbox"
}
},
{
"Name": "allowDelete",
"Label": "Allow Deletion",
"HelpText": "Is the File System allowed to be deleted. **TRUE OR FALSE** value must be entered\n\n**For example**: you don't want a production server to be deleted, the script will stop it from happening\n\n**HINT**: have a variable within Octopus that returns true if it is allowed to be deleted and vice versa.",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "Checkbox"
}
}
],
"Properties": {
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptBody": "#--------------------------------------------------------------------\n#Octopus Variables\n\n#URL of RavenFS that is being deleted \n$ravenFileSystemURL = $OctopusParameters[\"ravenFileSystemURL\"]\n\n#name of the RavenFS that is being deleted\n$ravenFileSystemName = $OctopusParameters[\"ravenFileSystemName\"]\n\n#hard delete (true or false)\n$hardDelete = $OctopusParameters[\"hardDelete\"]\n\n#Allow File System to be deleted\n$allowDelete = $OctopusParameters[\"allowDelete\"]\n\n\n\nWrite-Output \"`n-------------------------`n\"\n#--------------------------------------------------------------------\n#checks to see if the File System can be deleted\n\nif($allowDelete -eq $FALSE)\n{\n Write-Error \"$ravenFileSystemName cannot be deleted. Please try this on a database that can be delete.\" -ErrorId E4\n Exit 1\n}\n\n\n#--------------------------------------------------------------------\n\n#checks to see if the entered file system exists, return a Boolean value depending on the outcome\nfunction doesRavenFSExist([string] $FSChecking, [string]$URL)\n{\n #retrieves the list of File Systems at the specified URL\n $fs_list = Invoke-RestMethod -Uri \"$URL/fs\" -Method Get\n #checks if the File System is at the specified URL\n if ($fs_list -contains $FSChecking.ToString()) \n {\n return $TRUE\n }\n else \n {\n return $FALSE\n }\n\n \n}#ends does File System exist function\n\n\nWrite-Output \"`n-------------------------`n\"\n\n#--------------------------------------------------------------------\n#check to see if File System exists\n\nWrite-Output \"Checking if $ravenFileSystemName exists\"\n\n$fs_exists = doesRavenFSExist -FSChecking $ravenFileSystemName -URL $ravenFileSystemURL\n\nif($fs_exists -eq $TRUE)\n{\n Write-Output \"$ravenFileSystemName exists\"\n $doWork = $TRUE\n}\nelse\n{\n Write-Warning \"$ravenFileSystemName doesn't exist already.\"\n $doWork = $FALSE\n}\n\n#--------------------------------------------------------------------\n#converts hard delete option to a string\n\n$hardDeleteString = $hardDelete.ToString().ToLower()\n\n#--------------------------------------------------------------------\n#Delete File System\n\nif($doWork -eq $TRUE)\n{\n\n Write-Output \"Deleting File System: $ravenFileSystemName\"\n\n $deleteURI = \"$ravenFileSystemURL/admin/fs/$ravenFileSystemName\" + \"?hard-delete=$hardDeleteString\"\n\n Invoke-RestMethod -Uri $deleteURI -Method Delete\n\n\n #Waits 10 seconds before it continues\n Start-Sleep -Seconds 10\n \n Write-Output \"File System has successfuly been deleted\"\n\n}"
},
"Category": "RavenDB",
"HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/ravendb-delete-filesystem.json",
"Website": "/step-templates/365ae5c6-8f97-4e99-82c8-9973b9b0d8ff",
"Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADBQTFRF0Y6OjR8iHx8fW1la0szNmVZZZB8k5crLkIyMwl1evI6QwrCw6uPjsiAh////8/HxjiSEkQAABNlJREFUeNrs24uWmyAUBVBQkKfh//+2gKiYGKMRsWkPnbUmdZLUPfeBEUoe/8gggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggADy/0GceDpgpDSM/SCE9L1SxMweK5swWu/5rdQKlDAUmTCmbZqkYb9UIzZR+p4INxxishlHa1xViBNC7H0Lo5RZvrafBrHDIdY2maUixJ+L2v0W/nxfD41D2cRtsiHtXwAhzz9aQlSMj1CvlDantLYSxPeevRArRHZW/cBymWR0LoJSOirHi51sZ9103lml9GooONssKdUhhszN9CEI2apWn1pJmqdXP7zELtKraVlliHot563ZfQyZJYQo6hV0CtOTpDG1IfRACoqeqrxrJMpwzC0hTVsT4vTTTJFlmf0YHyF8VMIflSZHuWxf7q5iz19Me5F6nNJb7WGQ6LXmVaoRn4P0dIBQStWml8avGFYnL8muUxCjeIIMZeG7G5neMOiG2iKUJsrQ++LZLyXWZBnX+mtlVxWSnzMPTcF/p/NBf+YJEh4FDY/nZw1zbBGT5nW0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