Skip to content

Commit e636c84

Browse files
committedFeb 19, 2016
Merge pull request #295 from joaoasrosa/master
Add a template to execute SQL files.
2 parents 9909b8a + 5a3acd1 commit e636c84

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"Id": "ActionTemplates-168",
3+
"Name": "SQL - Execute Script File",
4+
"Description": "Execute a SQL script file",
5+
"ActionType": "Octopus.Script",
6+
"Version": 8,
7+
"Properties": {
8+
"Octopus.Action.Script.ScriptBody": "$connection = New-Object System.Data.SqlClient.SqlConnection\r$connection.ConnectionString = $OctopusParameters['ConnectionString']\rRegister-ObjectEvent -inputobject $connection -eventname InfoMessage -action {\r write-host $event.SourceEventArgs\r} | Out-Null\r\rfunction Execute-SqlQuery($query) {\r $command = $connection.CreateCommand()\r $command.CommandText = $query\r $command.CommandTimeout = $OctopusParameters['CommandTimeout']\r $command.ExecuteNonQuery() | Out-Null\r}\r\rWrite-Host \"Connecting\"\rtry {\r $connection.Open()\r Write-Host \"Executing script in\" $OctopusParameters['SqlScriptFile']\r $content = [IO.File]::ReadAllText($OctopusParameters['SqlScriptFile'])\r Execute-SqlQuery -query $content\r}\rcatch {\r\tif ($OctopusParameters['ContinueOnError']) {\r\t\tWrite-Host $_.Exception.Message\r\t}\r\telse {\r\t\tthrow\r\t}\r}\rfinally {\r Write-Host \"Closing connection\"\r $connection.Dispose()\r}",
9+
"Octopus.Action.Script.Syntax": "PowerShell"
10+
},
11+
"SensitiveProperties": {},
12+
"Parameters": [
13+
{
14+
"Name": "ConnectionString",
15+
"Label": "Connection string",
16+
"HelpText": "Connection string for the SQL connection. Example:\n\n Server=.\\SQLExpress;Database=OctoFX;Integrated Security=True;\n\nBind to a variable to provide different values for different environments.",
17+
"DefaultValue": null,
18+
"DisplaySettings": {
19+
"Octopus.ControlType": "SingleLineText"
20+
}
21+
},
22+
{
23+
"Name": "SqlScriptFile",
24+
"Label": "SQL Script File",
25+
"HelpText": "Script file to run. Can be bound to a variable. Text output by the PRINT statement in SQL will be logged to the deployment log. Use 'GO' to separate multiple commands.",
26+
"DefaultValue": "",
27+
"DisplaySettings": {
28+
"Octopus.ControlType": "SingleLineText"
29+
}
30+
},
31+
{
32+
"Name": "ContinueOnError",
33+
"Label": "Continue On Error",
34+
"HelpText": "If set to true, an error with the SQL statement will simply write to the log and not cause an error in the deployment.",
35+
"DefaultValue": "",
36+
"DisplaySettings": {
37+
"Octopus.ControlType": "Checkbox"
38+
}
39+
},
40+
{
41+
"Name": "CommandTimeout",
42+
"Label": "Command Timeout",
43+
"HelpText": "The SQL Command Timeout. By default is 30 seconds.",
44+
"DefaultValue": "30",
45+
"DisplaySettings": {
46+
"Octopus.ControlType": "SingleLineText"
47+
}
48+
}
49+
],
50+
"LastModifiedBy": "joaoasrosa",
51+
"$Meta": {
52+
"ExportedAt": "2016-02-17T11:54:47.761Z",
53+
"OctopusVersion": "3.2.8",
54+
"Type": "ActionTemplate"
55+
}
56+
}

0 commit comments

Comments
 (0)
Please sign in to comment.