Skip to content

Commit 60786f5

Browse files
nvarscarkirill-kravtsov-eb
authored andcommitted
adding errorscript to the failed result
1 parent e3b8ead commit 60786f5

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

internal/classes/DBOpsDeploymentStatus.class.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class DBOpsDeploymentStatus {
1010
[System.Nullable[datetime]] $StartTime
1111
[System.Nullable[datetime]] $EndTime
1212
[string[]] $DeploymentLog
13+
[string] $ErrorScript
1314

1415
DBOpsDeploymentStatus() {
1516
Add-Member -InputObject $this -MemberType ScriptProperty -Name Duration -Value {

internal/functions/Invoke-Deployment.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@
134134
if (!$Status.Successful) {
135135
# Throw output error if unsuccessful
136136
if ($Status.Error) {
137+
if ($Status.ErrorScript) {
138+
$Status.ErrorScript = $upgradeResult.errorScript.Name
139+
}
137140
throw $Status.Error
138141
}
139142
else {
@@ -353,7 +356,12 @@
353356
}
354357
finally {
355358
$status.EndTime = [datetime]::Now
356-
$status
359+
}
360+
if ($status.Successful) {
361+
return $status
362+
}
363+
else {
364+
return $status | Select-PSFObject -ShowProperty SourcePath, SqlInstance, Database, Successful, Error, Duration, ErrorScript
357365
}
358366
}
359367
}

tests/Install-DBOScript.Tests.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,23 @@ Describe "Install-DBOScript integration tests" -Tag $commandName, IntegrationTes
474474
$errorObject | Should Not BeNullOrEmpty
475475
$errorObject.Exception.Message | Should Be "There is already an object named 'a' in the database."
476476
}
477+
It "Should return failure results with SilentlyContinue" {
478+
$testResults = Install-DBOScript -Absolute -Path $tranFailScripts -SchemaVersionTable $logTable -DeploymentMethod NoTransaction @connParams -ErrorAction SilentlyContinue
479+
$testResults | Should -Not -Be $null
480+
$testResults.Successful | Should -Be $false
481+
$testResults.SqlInstance | Should Be $script:mssqlInstance
482+
$testResults.Database | Should Be $newDbName
483+
$testResults.SourcePath | Should Be $v1scripts
484+
$testResults.ConnectionType | Should Be 'SQLServer'
485+
$testResults.Configuration.SchemaVersionTable | Should BeNullOrEmpty
486+
$testResults.Error.Message | Should Be "There is already an object named 'a' in the database."
487+
$testResults.ErrorScript | Should -Be (Resolve-Path $v1scripts).Path
488+
$testResults.Scripts.Name | Should Be (Resolve-Path $v1scripts).Path
489+
$testResults.Duration.TotalMilliseconds | Should -BeGreaterOrEqual 0
490+
$testResults.StartTime | Should Not BeNullOrEmpty
491+
$testResults.EndTime | Should Not BeNullOrEmpty
492+
$testResults.EndTime | Should -BeGreaterOrEqual $testResults.StartTime
493+
}
477494
It "should not deploy anything after throwing an error" {
478495
#Running package
479496
try {

0 commit comments

Comments
 (0)