I have the output of an Invoke-sqlcmd in a text file.
I need to check the output for the word failed or failure and if it's found, I need to break
here is my code:
$var=Get-Content "C:\JenkinsDrops\TRGDB0632 tSQLt Report.txt"
$count = 0
foreach($item in $var -match "Failure"){
$count=$count+1
out-host $item.ToString()
}
the output looks like this:
[PayrollUnitTests].[test sp_GetEmployeePaySlipPayElements_Basic] failed: (Failure) Unexpected/missing resultset rows!
|_m_|Descn |Units|Rate |Amount|Category |isGross|
+---+--------------------------+-----+-----+------+---------+-------+
|< |Tronc Payment Caffe |0 |77.96|77.96 |Payment |False |
|= |Back Of House Tronc Caffe |1 |27.29|27.29 |Deduction|False |
|= |Champneys Springs Salaried|0 |0 |0.89 |Deduction|False |
|= |Hour Caffe |31 |7.2 |223.2 |Payment |False |
|= |NI |0 |0 |8.18 |Deduction|False |
|= |Tax |0 |0 |12.4 |Deduction|False |
|> |Tronc Payment Caffe |1 |77.96|77.96 |Payment |False |
+----------------------+
|Test Execution Summary|
+----------------------+
|No|Test Case Name |Dur(ms)|Result |
+--+----------------------------------------------------------------+-------+-------+
|1 |[PayrollUnitTests].[test fn_GetEmployeeBradfordFactor] | 413|Success|
|2 |[PayrollUnitTests].[test sp_GetEmployeeDetailsforPreview] | 220|Success|
|3 |[PayrollUnitTests].[test sp_GetEmployeesDetailsForCalc] | 520|Success|
|4 |[PayrollUnitTests].[test sp_GetP11DetailsForEmployee] | 290|Success|
|5 |[PayrollUnitTests].[test sp_UpdateEmployeeP11FromCalc] | 306|Success|
|6 |[PayrollUnitTests].[test sprc_BACS_UpdateBACSStatus] | 130|Success|
|7 |[PayrollUnitTests].[test sp_GetEmployeePaySlipPayElements_Basic]| 333|Failure|
any occurrence of the word "fail" or "Failure" means the tSQLt unit tests have failed and the deployment to QA cannot proceed
what's the best way to do that?