Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Liquori committed Mar 18, 2019
1 parent 7ecbc24 commit 817a735
Show file tree
Hide file tree
Showing 9 changed files with 381 additions and 0 deletions.
105 changes: 105 additions & 0 deletions Task/Invoke-OracleDatabase.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
[CmdletBinding()]
param ()

$ScriptPath = Get-VstsInput -Name 'scriptPath' -Require
$User = Get-VstsInput -Name 'user' -Require
$Password = Get-VstsInput -Name 'password' -Require
$DatabaseName = Get-VstsInput -Name 'databaseName' -Require
$LogPath = Get-VstsInput -Name 'logPath' -Require
$TopLine = Get-VstsInput -Name 'topLine' -Default true
$Define = Get-VstsInput -Name 'define' -Default true
$Echo = Get-VstsInput -Name 'echo' -Default true
$Timing = Get-VstsInput -Name 'timing' -Default true
$SqlError = Get-VstsInput -Name 'sqlError' -Default true
$Copy = Get-VstsInput -Name 'copy' -Default true
$Move = Get-VstsInput -Name 'move' -Default true

function Write-File {
param (
[System.IO.FileInfo]$FilePath,
[ValidateSet('UTF8','Default')]
[string]$Encoding = 'Default',
[Parameter(ValueFromPipeline)]
[string]$Value
)
Try {
Add-Content -Path $FilePath -Value $Value -Encoding $Encoding -ErrorAction Stop
}
Catch {
throw $_
}
}

function _Move {
param (
$Path,
$Destination
)
Try {
Move-Item -Path $Source -Destination $Destination -ErrorAction Stop
}
Catch {
Write-Warning "Could not move $Source to $Destination"
$_
}
}

function _Copy {
param (
$Path,
$Destination
)
Try {
Copy-Item -Path $Path -Destination $Destination -ErrorAction Stop
}
Catch {
Write-Warning "Could not copy $Path to $Destination"
$_
}
}

Try {
$SqlPath = (Find-VstsFiles -LegacyPath "$ScriptPath\**.sql" -ErrorAction Stop).FullName
Try {
New-Item -Path env:NLS_LANG -Value .AL32UTF8 -ErrorAction Stop
}
Catch {
if ($_ -like '*access denied*') {
throw $_
}
else {
Write-Verbose 'NLS_LANG environment variable already set.'
}
}
foreach ($SqlFile in $SqlPath) {
Write-Output "spool $($SqlFile).log" |Write-File -FilePath "$($SqlFile).run"
if ($TopLine) {
Write-Output "-- top line" |Write-File -FilePath "$($SqlFile).run"
}
if ($Define) {
Write-Output "set define off;" |Write-File -FilePath "$($SqlFile).run"
}
if ($Echo) {
Write-Output "set echo on;" |Write-File -FilePath "$($SqlFile).run"
}
if ($Timing) {
Write-Output "set timing on;" |Write-File -FilePath "$($SqlFile).run"
}
if ($SqlError) {
Write-Output "whenever sqlerror exit sql.sqlcode rollback;" |Write-File -FilePath "$($SqlFile).run"
}
Get-Content "$($SqlFile)" |Write-File -FilePath "$($SqlFile).run" -Encoding UTF8
Write-Output "spool off" |Write-File -FilePath "$($SqlFile).run"
Write-Output "exit" |Write-File -FilePath "$($SqlFile).run"
sqlplus "$User/$Password@$DatabaseName" "@$($SqlFile).run"
if ($Copy) {
_Copy -Path $SqlFile -Destination $LogPath
}
if ($Move) {
_Move -Path "$($SqlFile).log" -Destination $LogPath
}
}
}
Catch {
throw "No sql files exist at $ScriptPath"
}
Binary file added Task/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
134 changes: 134 additions & 0 deletions Task/task.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"id": "cde17640-4d22-410e-ae92-83ae8542e41c",
"name": "run-oracle-scripts",
"friendlyName": "Run Oracle Database Scripts",
"description": "Executes Oracle database scripts using sqlplus commandline tool.",
"author": "pwshliquori",
"helpMarkDown": "Executes Oracle database scripts using sqlplus commandline tool",
"category": "Deploy",
"visibility": [
"Release"
],
"demands": ["sqlplus.exe"],
"version": {
"Major": "1",
"Minor": "0",
"Patch": "0"
},
"groups": [
{
"name": "options",
"displayName": "Options",
"isExpanded": false
}
],
"instanceNameFormat": "Run Oracle Database Scripts",
"inputs": [
{
"name": "scriptPath",
"type": "filePath",
"label": "Script Path",
"defaultValue": "$(System.DefaultWorkingDirectory)",
"required": true,
"helpMarkDown": "Path of the Oracle scripts."
},
{
"name": "user",
"type": "string",
"label": "User",
"defaultValue": "",
"required": true,
"helpMarkDown": "User to connect to the Oracle database."
},
{
"name": "password",
"type": "string",
"label": "Password",
"defaultValue": "",
"required": true,
"helpMarkDown": "Password to connect to the Oracle database."
},
{
"name": "databaseName",
"type": "string",
"label": "Database Name",
"defaultValue": "",
"required": true,
"helpMarkDown": "Name of database for script to run on."
},
{
"name": "logPath",
"type": "textbox",
"label": "Log Path",
"defaultValue": "",
"required": false,
"groupName": "logging",
"helpMarkDown": "Path to save the log file after scripts have completed."
},
{
"name": "copy",
"type": "boolean",
"label": "Copy sql files to Log",
"defaultValue": true,
"required": false,
"groupName": "logging",
"helpMarkDown": "Copy .sql files to the log path."
},
{
"name": "move",
"type": "boolean",
"label": "Move sql log files to Log",
"defaultValue": true,
"required": false,
"groupName": "logging",
"helpMarkDown": "Move .log files generated from sqlplus to the log path."
},
{
"name": "topLine",
"type": "boolean",
"label": "Add --top line",
"defaultValue": true,
"groupName": "options",
"helpMarkDown": "Adds --top line to the script."
},
{
"name": "define",
"type": "boolean",
"label": "Set define off",
"defaultValue": true,
"groupName": "options",
"helpMarkDown": "Adds set define off to the script."
},
{
"name": "echo",
"type": "boolean",
"label": "Set echo on",
"defaultValue": true,
"groupName": "options",
"helpMarkDown": "Adds set echo on to the script."
},
{
"name": "timing",
"type": "boolean",
"label": "Set timing on",
"defaultValue": true,
"groupName": "options",
"helpMarkDown": "Adds set timing on to the script."
},
{
"name": "sqlError",
"type": "boolean",
"label": "Exit on sqlerror",
"defaultValue": true,
"groupName": "options",
"helpMarkDown": "Adds whenever sqlerror exit sql.sqlcode rollback to the script."
}
],
"execution": {
"PowerShell3": {
"target": "$(currentDirectory)/Invoke-OracleDatabase.ps1",
"argumentFormat": "",
"workingDirectory": "$(currentDirectory)"
}
}
}
5 changes: 5 additions & 0 deletions Tests/Invoke-OracleDatabase.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Describe 'Invoke-OracleDatabase' {
It 'Should have sqlplus installed' {
{sqlplus -v} |Should Not throw
}
}
31 changes: 31 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
resources:
- repo: self
pool:
name: OnPrem VS2017
workspace:
clean: all
name: $(Date:yyyyMMdd)$(Rev:.r)
trigger:
branches:
include:
- master
paths:
exclude:
- azure-pipelines.yml
- Tests/*
variables:
Name: run-oracle-scripts
steps:
- task: ms-devlabs.vsts-developer-tools-build-tasks.package-extension-build-task.PackageVSTSExtension@1
displayName: 'Package Extension: $(Name)'
inputs:
extensionVisibility: private
extensionPricing: free
- task: CopyFiles@2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(Build.SourcesDirectory)'
Contents: 'pwshliquori.$(Name)*'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Run Oracle Database Scripts

Executes Oracle database scripts using sqlplus commandline tool.

## Details

Task can run multiple database scripts during a release.

## How it works

Task will look for .sql files in a specified directory to run sqlplus against a database. Options can be added to the sql file to enhance functionality of the script.

## Note

Sqlplus.exe must be available before running this task.

Run Pester test located under "Tests" folder to verify sqlplus is installed.

## Changelog

Version 0.0.1
- Create function to add log file path
- Create function to add options to the .run file
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "run-oracle-scripts",
"version": "0.0.1",
"private": true,
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"vss-web-extension-sdk": "^5.141.0"
}
}
72 changes: 72 additions & 0 deletions vss-extension.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"manifestVersion": 1,
"id": "run-oracle-scripts",
"name": "Run Oracle Database Scripts",
"description": "Executes Oracle database scripts using sqlplus commandline tool.",
"version": "0.0.1",
"publisher": "pwshliquori",
"public": false,
"baseUri": "https://github.com/USF-HII",
"scopes": [],
"tags": [
"Oracle",
"sql",
"sqlplus"
],
"links": {
"home": {
"uri": "https://github.com/USF-HII/azuredevops-extension-run-oracle-scripts"
},
"learn": {
"uri": "https://github.com/USF-HII/azuredevops-extension-run-oracle-scripts"
},
"support": {
"uri": "https://github.com/USF-HII/azuredevops-extension-run-oracle-scripts/issues"
},
"repository": {
"uri": "https://github.com/USF-HII/azuredevops-extension-run-oracle-scripts"
}
},
"repository": {
"type": "git",
"uri": "https://github.com/USF-HII/azuredevops-extension-run-oracle-scripts"
},
"branding": {
"color": "rgb(0, 114, 186)",
"theme": "dark"
},
"targets": [
{
"id": "Microsoft.VisualStudio.Services"
}
],
"categories": [
"Azure Pipelines"
],
"icons": {
"default": "logo.png"
},
"files": [
{ "path": "Task" }
],
"content": {
"details": {
"path": "overview.md"
},
"license": {
"path": "license.md"
}
},
"contributions": [
{
"id": "run-oracle-scripts",
"type": "ms.vss-distributed-task.task",
"targets": [
"ms.vss-distributed-task.tasks"
],
"properties": {
"name": "Task"
}
}
]
}

0 comments on commit 817a735

Please sign in to comment.