Skip to content

Commit dd3da22

Browse files
authored
Merge pull request #1269 from microsoft/users/v-abhishera/enhacingSqlDacPacDeploymentOnMachineGroupV0
Enhanced the functionality of SqlDacPacDeploymentonOnMachineGroupV0
2 parents cda6821 + 244bab9 commit dd3da22

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

TaskModules/powershell/TaskModuleSqlUtility/SqlQueryOnTargetMachines.ps1

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# Function to import SqlPS module & avoid directory switch
1+
$featureFlags = @{
2+
enableVerboseLogging = [System.Convert]::ToBoolean($env:ENABLE_VERBOSE_LOGGING)
3+
}
4+
# Function to import SqlPS module & avoid directory switch
25
function Import-SqlPs {
36
push-location
47
Import-Module SqlPS -ErrorAction 'SilentlyContinue' | out-null
@@ -86,10 +89,38 @@ function Invoke-SqlQueryDeployment
8689
}
8790

8891
$additionalArguments = EscapeSpecialChars $additionalArguments
92+
if ($featureFlags.enableVerboseLogging) {
93+
$commandToRun = $commandToLog + " " + $additionalArguments
94+
$command = "Invoke-SqlCmd @spaltArguments $additionalArguments"
95+
Write-Host "##[command] $commandToRun"
96+
97+
if ($additionalArguments.ToLower().Contains("-verbose")) {
98+
$errors = @()
8999

90-
Write-Verbose "Invoke-SqlCmd arguments : $commandToLog $additionalArguments"
91-
Invoke-Expression "Invoke-SqlCmd @spaltArguments $additionalArguments"
100+
Invoke-Expression $command -ErrorVariable errors 4>&1 | ForEach-Object {
101+
Write-Host $_
102+
}
92103

104+
if ($errors.Count -gt 0) {
105+
throw
106+
}
107+
}
108+
else {
109+
Invoke-Expression $command
110+
}
111+
}
112+
else {
113+
Write-Verbose "Invoke-SqlCmd arguments : $commandToLog $additionalArguments"
114+
Invoke-Expression "Invoke-SqlCmd @spaltArguments $additionalArguments"
115+
}
116+
}
117+
Catch {
118+
if ($featureFlags.enableVerboseLogging) {
119+
Write-VstsSetResult -Result 'Failed' -Message "Error detected" -DoNotThrow
120+
}
121+
else {
122+
throw $_.Exception
123+
}
93124
} # End of Try
94125
Finally
95126
{

TaskModules/powershell/TaskModuleSqlUtility/TaskModuleSqlUtility.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
RootModule = 'TaskModuleSqlUtility.psm1'
3-
ModuleVersion = '0.1.3'
3+
ModuleVersion = '0.1.6'
44
GUID = 'd997c6dd-33ad-481c-859b-01120229b91f'
55
Author = 'Microsoft'
66
CompanyName = 'Microsoft'

0 commit comments

Comments
 (0)