Functions/Get-XmlTestResults.ps1

Function Get-XmlTestResults {
    param(
        $NotebookTest
    )
    $DatabricksJobRun = $null
    $noteBookOutput = $null
    $ClusterId = Get-CachedDatabricksClusterId -ClusterName $NotebookTest.testClusterName
    $DatabricksNotebookJob = @{
        JobName      = $NotebookTest.jobName
        ClusterId    = $ClusterId
        NotebookPath = $NotebookTest.notebookPath
        RunImmediate = $true
    }
    if ($NotebookTest.notebookparamsjson) {                        
        $DatabricksNotebookJob.add("NotebookParametersJson", $NotebookTest.notebookparamsjson)            
    } 
    $runId = Add-DatabricksNotebookJob @DatabricksNotebookJob
    Write-Host "Run ID - "$runId
    Write-Host "Running tests. This is the info for the job running the tests..."
    Get-DatabricksRun -RunId $runId
    $DatabricksJobRunState = $null
    $wait = 1
    $currentStatus = "INITIATED"
    Write-Host "There is a 20 minute timeout for test jobs."
    do {
        Start-Sleep -Seconds 10
        $DatabricksJobRunState = Get-DatabricksRun -RunId $runId     
        $DatabricksJobRunLifeCycleState = $DatabricksJobRunState.state.life_cycle_state
        if ($currentStatus -ne $DatabricksJobRunLifeCycleState) {
            Write-Host "Status has altered from $currentStatus to $DatabricksJobRunLifeCycleState."
            $currentStatus = $DatabricksJobRunLifeCycleState
        }
        if (($wait % 5) -eq 0) {
            Write-Host "Job has not completed. Status is $DatabricksJobRunLifeCycleState."
        }
        $wait ++
    } until (($DatabricksJobRunLifeCycleState -notin "PENDING", "RUNNING", "TERMINATING", "SKIPPED", "INTERNAL_ERROR") -or ($wait -eq 120))
    Write-Host "Test Completed. Check here for the status of the job."
    $databricksRun = Get-DatabricksRun -RunId $runId     
    if ($databricksRun.state.result_state -ne "SUCCESS") {
        $databricksRun
        Write-Error "Job failed. Use url to open job and investigate"
        throw
    }
    $DatabricksJobRun = Get-DatabricksJobRun -RunId $runId -includeNoteBookOutput
    if ($null -eq $DatabricksJobRun.notebook_output.result) {
        Write-Host "Job succeeded, but no result, so notebook most likely failed. Use url to open job and investigate"
        Throw
    }
    $DatabricksJobRun = Get-DatabricksJobRun -RunId $runId -includeNoteBookOutput
    $DatabricksJobRun | ConvertTo-Json | Out-File .\"NotebooksTest_$($NotebookTest.jobName)_$($runId).json"
    Write-Verbose $DatabricksJobRun
    $noteBookOutput = $DatabricksJobRun.notebook_output.result
    Write-Verbose $noteBookOutput

    $noteBookOutput | Out-File .\"NotebooksTest_$($NotebookTest.jobName)_$($runId).xml" -Force
}