Octopus.Script exported 2019-03-21 by octobob belongs to ‘Oracle’ category.
This step will run a script file on an Oracle database using SQLPlus. This script assumes you have SQLPlus installed and a TNS entry for the database you wish to connect to.
Parameters
When steps based on the template are included in a project’s deployment process, the parameters below can be set.
Script File To Run
Oracle.ScriptFile.Location =
The script file to run on the Oracle server
TNS Name
Oracle.Server.Name =
The TNS entry in tnsnames.ora containing the necessary connection information.
Oracle Username
Oracle.User.Name =
The user who has permissions to run the script file on the server
Oracle User Password
Oracle.User.Password =
The password of the user who will run the script
Script body
Steps based on this template will execute the following PowerShell script.
$scriptFile = $OctopusParameters["Oracle.ScriptFile.Location"]
$server = $OctopusParameters["Oracle.Server.Name"]
$user = $OctopusParameters["Oracle.User.Name"]
$password = $OctopusParameters["Oracle.User.Password"]
Write-Host "Script File: $scriptFile"
Write-Host "Oracle Server: $server"
Write-Host "Oracle Username: $user"
Write-Host "Oracle Password not shown"
If ((Test-Path $scriptFile) -eq $true){
Write-Host "Script file found, running on the database"
$maskedConnectionString = "$user/*****@$server/$deploymentSchema"
$unmaskedConnectionString = "$user/$password@$server"
Write-Host "Running the script against: $maskedConnectionString"
Write-Host "Adding to the top of the script file WHENEVER SQLERROR EXIT SQL.SQLCODE"
$scriptToHandleErrors = "WHENEVER SQLERROR EXIT SQL.SQLCODE
"
$old = Get-Content $scriptFile
Set-Content -Path $scriptFile -Value $scriptToHandleErrors
Add-Content -Path $scriptFile -Value $old
echo exit | sqlplus $unmaskedConnectionString @$scriptFile
}
else {
Write-Highlight "No script file was found. If the script file should be there please verify the location and try again."
}
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": "c7cd3ab4-5dfb-4f8d-957e-1940ed30359c",
"Name": "Run Oracle SQLPlus Script",
"Description": "This step will run a script file on an Oracle database using SQLPlus. This script assumes you have SQLPlus installed and a TNS entry for the database you wish to connect to.",
"Version": 3,
"ExportedAt": "2019-03-21T20:12:11.956Z",
"ActionType": "Octopus.Script",
"Author": "octobob",
"Packages": [],
"Parameters": [
{
"Id": "2aa011b3-ab2b-4de9-a09c-abb20cbbd55e",
"Name": "Oracle.ScriptFile.Location",
"Label": "Script File To Run",
"HelpText": "The script file to run on the Oracle server",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Id": "36161c93-a70d-472d-a31a-d8cba42ee087",
"Name": "Oracle.Server.Name",
"Label": "TNS Name",
"HelpText": "The TNS entry in tnsnames.ora containing the necessary connection information.",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Id": "1e1cc9f3-486e-4df2-bb9c-e7dd7d1918f7",
"Name": "Oracle.User.Name",
"Label": "Oracle Username",
"HelpText": "The user who has permissions to run the script file on the server",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Id": "bbf4eb93-fbda-4740-b782-88480183d77c",
"Name": "Oracle.User.Password",
"Label": "Oracle User Password",
"HelpText": "The password of the user who will run the script",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "Sensitive"
}
}
],
"Properties": {
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptBody": "$scriptFile = $OctopusParameters[\"Oracle.ScriptFile.Location\"]\n$server = $OctopusParameters[\"Oracle.Server.Name\"]\n$user = $OctopusParameters[\"Oracle.User.Name\"]\n$password = $OctopusParameters[\"Oracle.User.Password\"]\n\nWrite-Host \"Script File: $scriptFile\"\nWrite-Host \"Oracle Server: $server\"\nWrite-Host \"Oracle Username: $user\"\nWrite-Host \"Oracle Password not shown\"\n\nIf ((Test-Path $scriptFile) -eq $true){\n Write-Host \"Script file found, running on the database\"\n \n $maskedConnectionString = \"$user/*****@$server/$deploymentSchema\"\n $unmaskedConnectionString = \"$user/$password@$server\"\n Write-Host \"Running the script against: $maskedConnectionString\"\n \n Write-Host \"Adding to the top of the script file WHENEVER SQLERROR EXIT SQL.SQLCODE\"\n $scriptToHandleErrors = \"WHENEVER SQLERROR EXIT SQL.SQLCODE\n \"\n \n $old = Get-Content $scriptFile\n Set-Content -Path $scriptFile -Value $scriptToHandleErrors\n Add-Content -Path $scriptFile -Value $old\n\n echo exit | sqlplus $unmaskedConnectionString @$scriptFile\n}\nelse {\n\tWrite-Highlight \"No script file was found. If the script file should be there please verify the location and try again.\"\n}"
},
"Category": "Oracle",
"HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/oracle-run-script-through-sqlplus.json",
"Website": "/step-templates/c7cd3ab4-5dfb-4f8d-957e-1940ed30359c",
"Logo": "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjEuMWMqnEsAAAX6SURBVHhe7df5jxRVEAdw/gwEhOVYLjkElEMEFBYUMIJHJIpR0Qge6y1RFAkgXlFRCKsoERSVYFAg4Kq/qCiiCGhgEQEjaqJiOLanZ2dm5+iZKauqZ9md6YKdEIbqH4rkk2W/8/q9N6/6ve7tAAAmRMTQ6BFDo0cMjR4xNHrE0OgRQ6NHDI0eMTR6xNDoEUOjRwyNHjE0esTQ6BFDo0cMjR4xNHrE0OgRQ6NHDI0eMTR6xNDoEUOjRwyNHjE0esTQ6BFDo0cMjR4xNHrE0OgRQ6NHDI0eMTR6AoFbMxnM+VO6/kW/kMauvcCcP8k17+GyW0FCwwoSMlaQkLGChIwVJGSsICFjBQkZK0jIWEFCxgoSMpUtSJce/s8efYO6o07di9t37yO3JdS+c6E/yYU9wek3mH+KnxOaT9XpxuiHbarB6dnfbyNdX6pTlT8vqT/KaU59Bp55TiUqVhBanObldZA7fhwgmw1Kp8Fr2A+x2ff7E8bipDZ8Irct8H45ANHJ04Lj4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