Created
July 31, 2017 12:59
-
-
Save Wesley-Lomax/670450bea853e762e3ff19a304956186 to your computer and use it in GitHub Desktop.
Octopus Deploy - File System Zip Step
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$SourceDirectoryName = $OctopusParameters['SourceDirectoryName'] | |
$DestinationArchiveFileName = $OctopusParameters['DestinationArchiveFileName'] | |
$CompressionLevel = $OctopusParameters['CompressionLevel'] | |
$IncludeBaseDirectory = $OctopusParameters['IncludeBaseDirectory'] | |
$OverwriteDestination = $OctopusParameters['OverwriteDestination'] | |
if (!$SourceDirectoryName) | |
{ | |
Write-Error "No Source Directory name was specified. Please specify the name of the directory to that will be zipped." | |
exit -2 | |
} | |
if (!$DestinationArchiveFileName) | |
{ | |
Write-Error "No Destination Archive File name was specified. Please specify the name of the zip file to be created." | |
exit -2 | |
} | |
if (($OverwriteDestination) -and (Test-Path $DestinationArchiveFileName)) | |
{ | |
Write-Host "$DestinationArchiveFileName already exists. Will delete it before we create a new zip file with the same name." | |
Remove-Item $DestinationArchiveFileName | |
} | |
Write-Host "Creating Zip file $DestinationArchiveFileName with the contents of directory $SourceDirectoryName using compression level $CompressionLevel" | |
[Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | |
[System.IO.Compression.ZipFile]::CreateFromDirectory($SourceDirectoryName, $DestinationArchiveFileName, $CompressionLevel, $IncludeBaseDirectory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Id": "ActionTemplates-2", | |
"Name": "File System - Zip Directory Contents", | |
"Description": "Creates a zip archive that contains the files and directories from the specified directory, uses the specified compression level, and optionally includes the base directory.\n\nRequires .NET 4.5 as it relies on the `System.IO.Compression.ZipFile` class.", | |
"ActionType": "Octopus.Script", | |
"Version": 3, | |
"Properties": { | |
"Octopus.Action.Script.ScriptBody": "$SourceDirectoryName = $OctopusParameters['SourceDirectoryName']\n$DestinationArchiveFileName = $OctopusParameters['DestinationArchiveFileName']\n$CompressionLevel = $OctopusParameters['CompressionLevel']\n$IncludeBaseDirectory = $OctopusParameters['IncludeBaseDirectory']\n$OverwriteDestination = $OctopusParameters['OverwriteDestination']\n\nif (!$SourceDirectoryName)\n{\n Write-Error \"No Source Directory name was specified. Please specify the name of the directory to that will be zipped.\"\n exit -2\n}\n\nif (!$DestinationArchiveFileName)\n{\n Write-Error \"No Destination Archive File name was specified. Please specify the name of the zip file to be created.\"\n exit -2\n}\n\nif (($OverwriteDestination) -and (Test-Path $DestinationArchiveFileName))\n{\n Write-Host \"$DestinationArchiveFileName already exists. Will delete it before we create a new zip file with the same name.\"\n Remove-Item $DestinationArchiveFileName\n}\n\nWrite-Host \"Creating Zip file $DestinationArchiveFileName with the contents of directory $SourceDirectoryName using compression level $CompressionLevel\"\n\n[Reflection.Assembly]::LoadWithPartialName(\"System.IO.Compression.FileSystem\")\n[System.IO.Compression.ZipFile]::CreateFromDirectory($SourceDirectoryName, $DestinationArchiveFileName, $CompressionLevel, $IncludeBaseDirectory)\n", | |
"Octopus.Action.Script.Syntax": "PowerShell", | |
"Octopus.Action.Script.ScriptSource": "Inline" | |
}, | |
"Parameters": [ | |
{ | |
"Name": "SourceDirectoryName", | |
"Label": "Source Directory", | |
"HelpText": "The path to the directory to be archived, specified as a relative or absolute path.", | |
"DefaultValue": null, | |
"DisplaySettings": { | |
"Octopus.ControlType": "SingleLineText" | |
} | |
}, | |
{ | |
"Name": "DestinationArchiveFileName", | |
"Label": "Destination Archive File", | |
"HelpText": "The path of the archive to be created, specified as a relative or absolute path.", | |
"DefaultValue": null, | |
"DisplaySettings": { | |
"Octopus.ControlType": "SingleLineText" | |
} | |
}, | |
{ | |
"Name": "CompressionLevel", | |
"Label": "Compression Level", | |
"HelpText": "Indicates whether to emphasize speed or compression effectiveness when creating the entry.", | |
"DefaultValue": "Optimal", | |
"DisplaySettings": { | |
"Octopus.ControlType": "Select", | |
"Octopus.SelectOptions": "Optimal|Optimal\nFastest|Fastest\nNoCompression|No Compression" | |
} | |
}, | |
{ | |
"Name": "IncludeBaseDirectory", | |
"Label": "Include Base Directory", | |
"HelpText": "Include the directory name from Source Directory at the root of the archive.", | |
"DefaultValue": null, | |
"DisplaySettings": { | |
"Octopus.ControlType": "Checkbox" | |
} | |
}, | |
{ | |
"Name": "OverwriteDestination", | |
"Label": "Overwrite Destination If Exists", | |
"HelpText": "Overwrite the destination archive file if it already exists.", | |
"DefaultValue": null, | |
"DisplaySettings": { | |
"Octopus.ControlType": "Checkbox" | |
} | |
} | |
], | |
"$Meta": { | |
"ExportedAt": "2017-07-31T12:58:47.704Z", | |
"OctopusVersion": "3.3.4", | |
"Type": "ActionTemplate" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment