AzDOTestResults.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
using namespace System.IO
using namespace System.Text

Set-StrictMode -Version 'Latest'
#Requires -Version 5.0

$PSDefaultParameterValues.Clear()

function Get-BuildEnvironment {
<#
  .SYNOPSIS
  Gathers the appropriate build environment variables in Azure DevOps
  required for the download process and returns a custom object containing
  the values
#>

    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    param()
    process {
        [PSCustomObject](@{
                OrganizationUri = $env:SYSTEM_TEAMFOUNDATIONSERVERURI
                Project         = $env:SYSTEM_TEAMPROJECT
                AccessToken     = $env:SYSTEM_ACCESSTOKEN
                BuildUri        = $env:BUILD_BUILDURI
                CommonTestResultsFolder = $env:COMMON_TESTRESULTSDIRECTORY
                TempTestResultsFolder = "$env:AGENT_TEMPDIRECTORY/TestResults"
                ProjectUri      = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)/$($env:SYSTEM_TEAMPROJECT)"
            })
    }
}

function Get-AuthorizationHeader {
<#
  .SYNOPSIS
  Creates the HTTP Authorization Header.
#>

    [CmdletBinding()]
    [OutputType([string])]
    param(
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]$Token
    )

    process {
        "Basic " + [Convert]::ToBase64String([Encoding]::ASCII.GetBytes(("{0}:{1}" -f '', $Token)))
    }
}

function Get-TrxAttachmentList {
<#
  .SYNOPSIS
  Gets the list of coverage attachments from a TRX file.
#>

    [CmdletBinding()]
    [OutputType([string[]])]
    param(
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [ValidateNotNullOrEmpty()]
        [string] $FilePath
    )

    process {
        $xml = [xml] (Get-Content $FilePath -ErrorAction Stop)
        $ns = New-Object Xml.XmlNamespaceManager $xml.NameTable
        $ns.AddNamespace( "ns", 'http://microsoft.com/schemas/VisualStudio/TeamTest/2010')
        $nodes = $xml.SelectNodes('//ns:UriAttachments/ns:UriAttachment/ns:A/@href', $ns) | Select-Object -ExpandProperty '#text'
        $nodes
    }
}

function Get-TestRunList {
<#
  .SYNOPSIS
  Invokes an Azure DevOps REST call to retrieve the list of test runs associated with the build
 
  .PARAMETER BuildUri
  The URI of the build associated with the tests
 
  .PARAMETER BaseUri
  The base URI containing the organization name and project name, such
  as https://dev.azure.com/myOrg/myProject.
 
  .PARAMETER AccessToken
  A PAT token or build access token providing authorization for the request
#>

    [CmdletBinding()]
    [OutputType([psobject[]])]
    param(
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
        [ValidateNotNullOrEmpty()]
        [string] $BuildUri,

        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
        [ValidateNotNullOrEmpty()]
        [string] $BaseUri,

        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
        [ValidateNotNullOrEmpty()]
        [string] $AccessToken
    )

    process {
        $AuthHeader = Get-AuthorizationHeader $AccessToken

        $params = @{
            Uri     = "$BaseUri/_apis/test/runs?api-version=5.0&buildUri=$BuildUri"
            Headers = @{
                Authorization = $AuthHeader
                Accept        = 'application/json'
            }
            Method  = 'Get'
        }

        $content = (Invoke-WebRequestWithRetry -Parameters $params).Content
        Write-Verbose "Received $content"
        ($content | ConvertFrom-Json).value
    }
}

function Get-TestAttachmentList {
<#
  .SYNOPSIS
  Invokes an Azure DevOps REST call to retrieve the test run details for a specific test
 
  .PARAMETER TestUri
  The URI for retrieving the test details
 
  .PARAMETER AccessToken
  A PAT token or build access token providing authorization for the request
#>

    [CmdletBinding()]
    [OutputType([psobject[]])]
    param(

        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string] $TestUri,

        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string] $AccessToken
    )

    process {
        $AuthHeader = Get-AuthorizationHeader $AccessToken

        $params = @{
            Uri     = "$TestUri/attachments?api-version=5.0-preview.1"
            Headers = @{
                Authorization = $AuthHeader
                Accept        = 'application/json'
            }
            Method  = 'Get'
        }

        $content = (Invoke-WebRequestWithRetry -Parameters $params).Content
        Write-Verbose "Received $content"
        [PsCustomObject[]]($content | ConvertFrom-Json).value
    }
}

function Get-TestAttachment {
<#
  .SYNOPSIS
  Invokes an Azure DevOps REST call to retrieve a specific test attachment
 
  .PARAMETER AttachmentUri
  The URI for retrieving the test attachment
 
  .PARAMETER OutputPath
  The absolute path to a folder or file where the content should be saved.
 
  .PARAMETER AccessToken
  A PAT token or build access token providing authorization for the request
#>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string] $AttachmentUri,


        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string] $OutputPath,

        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string] $AccessToken
    )

    process {
        $AuthHeader = Get-AuthorizationHeader $AccessToken

        $params = @{
            Uri     = $AttachmentUri
            Headers = @{
                Authorization = $AuthHeader
                Accept        = 'application/octet-stream'
            }
            Method  = 'Get'
            OutFile = $OutputPath
        }

        Write-Verbose "Downloading '$AttachmentUri' to '$OutputPath'"
        Invoke-WebRequestWithRetry $params
    }
}

function Join-FilePath {
<#
  .SYNOPSIS
  Combines two filesystem paths and returns the full path, with proper OS-specific
  directory separators
#>

    [CmdletBinding()]
    [OutputType([string])]
    param(
        [ValidateNotNullOrEmpty()]
        [Parameter(Mandatory = $true, Position = 0)]
        [string] $Path,

        [ValidateNotNullOrEmpty()]
        [Parameter(Mandatory = $true, Position = 1)]
        [string] $ChildPath
    )
    process {
        $combinedPath = [Path]::Combine($Path, $ChildPath)
        [Path]::GetFullPath($combinedPath)
    }
}

function Invoke-WebRequestWithRetry {
<#
  .SYNOPSIS
  A variant of the Invoke-WebRequest method which supports automatic retries
#>

    [CmdletBinding()]
    [OutputType([psobject])]
    param(
        [Parameter(Mandatory = $true, Position = 0)]
        [ValidateNotNull()]
        [hashtable] $Parameters,

        [ValidateRange(1, 100)]
        [int] $MaxRetries = 3,

        [ValidateRange(0, 16000)]
        [int] $SleepTime = 1000
    )

    process {
        $isComplete = $true
        $retryCount = 0
        do {
            try {
                $result = Invoke-WebRequest @Parameters -ErrorAction Stop -UseBasicParsing
                $isComplete = $true
                $result
            }
            catch {
                Write-Verbose $_.Exception
                if ($retryCount -ge $MaxRetries) {
                    $isComplete = $true
                    Throw (New-Object InvalidOperationException("Failed after $MaxRetries retries, $_.Exception"))
                }
                else {
                    $retryCount ++
                    $isComplete = $false
                    Write-Verbose "Failed: Retry $retryCount of $MaxRetries"
                    Start-Sleep -Milliseconds $SleepTime
                }
            }
        } while (-not $isComplete)
    }
}

function Group-TestAttachmentList {
<#
  .SYNOPSIS
  Gathers the list of attachments into files which represent Test Run Summaries (TRX files)
  and all other content
#>

    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
        [ValidateNotNull()]
        [PSCustomObject[]] $Attachments
    )

    process {
        $trxFiles = New-Object System.Collections.ArrayList
        $otherFiles = New-Object System.Collections.ArrayList
        foreach ($attachment in $Attachments) {
            if ('attachmentType' -in $attachment.PSobject.Properties.name) {
                $attachmentType = ($attachment | Select-Object -ExpandProperty 'attachmentType' -First 1)
                if ('tmiTestRunSummary' -eq $attachmentType) {
                    [void]$trxFiles.Add($attachment)
                }
                else {
                    [void]$otherFiles.Add($attachment)
                }
            }
            else {
                $extension = [Path]::GetExtension($attachment.fileName)
                if ('.trx' -eq $extension) {
                    [void]$trxFiles.Add($attachment)
                }
                else {
                    [void]$otherFiles.Add($attachment)
                }
            }
        }
        [PsCustomObject]@{
            TrxContent   = $trxFiles.ToArray()
            OtherContent = $otherFiles.ToArray()
        }
    }
}

function Get-GroupedAttachmentList {
<#
  .SYNOPSIS
  Downloads the list of test attachments and groups the results of files which represent
  Test Run Summaries (TRX files) and all other content
#>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
        [ValidateNotNullOrEmpty()]
        [Uri] $TestUri,

        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
        [ValidateNotNullOrEmpty()]
        [string] $AccessToken
    )
    process {
        $attachments = Get-TestAttachmentList -TestUri $TestUri -AccessToken $AccessToken
        Group-TestAttachmentList -Attachments $attachments
    }
}

function Get-TrxContent {
<#
  .SYNOPSIS
  Downloads the TRX file and returns an array of expected child content paths.
#>

    [CmdletBinding()]
    [OutputType([string[]])]
    param(
        [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
        [ValidateNotNull()]
        [PsCustomObject[]] $Files,

        [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 1)]
        [ValidateNotNull()]
        [string] $OutputFolder,

        [Parameter(ValueFromPipeline = $true)]
        [string] $TrxDependencyPath = '$trxFolder/In/$folder'
    )
    process {
        $trxChildPaths = New-Object System.Collections.ArrayList
        foreach ($trxFile in $Files) {
            Write-Verbose "Downloading TRX: $($trxFile.fileName)"
            $trxFolder = [Path]::GetFileNameWithoutExtension($trxFile.fileName).Replace(' ', '_')
            $trxDirectoryName = Join-FilePath -Path $OutputFolder -ChildPath $trxFolder
            Write-Verbose "Configuring TRX folder: $trxDirectoryName"
            $trxAttachments = Get-TrxAttachmentList -FilePath (Join-FilePath -Path $OutputFolder -ChildPath $trxFile.fileName)
            Write-Verbose "Processing attachments"
            foreach ($node in $trxAttachments) {
                $normalizedNode = (Join-Path -Path '.' -ChildPath $node).Substring(2)
                $folder = [Path]::GetDirectoryName($normalizedNode)
                Write-Verbose "$node => $folder"
                if ($TrxDependencyPath.StartsWith('/') -or $TrxDependencyPath.StartsWith('\')) {
                    $TrxDependencyPath = $TrxDependencyPath.Substring(1)
                }

                $expandedPath = $ExecutionContext.InvokeCommand.ExpandString($TrxDependencyPath)
                if ($expandedPath) {
                    $nodePath = Join-FilePath -Path $OutputFolder -ChildPath $expandedPath
                }
                else {
                    $nodePath = $OutputFolder
                }

                $nodeFileName = [Path]::GetFileName($node)
                Write-Verbose "The file '$nodeFileName' will be stored at '$nodePath'"
                $path = Join-FilePath -Path $nodePath -ChildPath $nodeFileName
                [void]$trxChildPaths.Add($path)
            }
        }

        $trxChildPaths.ToArray()
    }
}

function Group-ChildContent {
<#
  .SYNOPSIS
  Determines the proper file locations for a set of files given the list of TRX child paths,
  the content files being downloaded, and the Output Folder and returns a hash list of file
  names and their destinations.
 
  .PARAMETER TrxContentList
  The list of paths for expected TRX child content
 
  .PARAMETER FileList
  The list of files to be examined
 
  .PARAMETER OutputFolder
  The output destination for non-TRX children
#>

    [CmdletBinding()]
    [OutputType([hashtable])]
    param(
        [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
        [ValidateNotNull()]
        [string[]] $TrxContentList,

        [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 1)]
        [ValidateNotNull()]
        [string[]] $FileList,

        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [ValidateNotNull()]
        [string] $OutputFolder
    )
    process {
        $fileHash = @{ }
        $files = $FileList | Get-Unique
        if ($null -ne $TrxContentList) {
            $childContent = $files | Where-Object { [Path]::GetExtension($_) -eq '.coverage' }
            # foreach child get the matching TRX reference
            foreach ($child in $childContent) {
                $outArr = [array]($TrxContentList | Where-Object { [Path]::GetFileName($_) -eq  $child })
                [void]$fileHash.Add($child, $outArr)
            }

            $simpleContent = $files | Where-Object { $childContent -notcontains $_ }
            $simpleContent | Foreach-Object { [void]$fileHash.Add($_,  "$OutputFolder/$_" ) }
        }
        else {
            $files | Foreach-Object { [void]$fileHash.Add($_, "$OutputFolder/$_" ) }
        }
        $fileHash
    }
}

function Copy-TestResultToCommon {
<#
 .SYNOPSIS
 Retrieves test results for SonarQube from the current Azure DevOps build and places them in the
 Common Test Results folder ($Common.TestResultsDirectory)
 
 .DESCRIPTION
 Retrieves the test attachments from a build and places them in appropriate locations
 for SonarQube. This method expects the Azure DevOps environment variables to be set
 in order to automatically determine the location and build identity. This method calls
 Copy-TestResult using the appropriate Azure DevOps environment variables.
 
 .EXAMPLE
 Copy-TestResultToCommon
#>

    [CmdletBinding()]
    param()
    process {
        $buildEnv = Get-BuildEnvironment
        Copy-TestResult -ProjectUri $buildEnv.ProjectUri -AccessToken $buildEnv.AccessToken -BuildUri $buildEnv.BuildUri -OutputFolder $buildEnv.CommonTestResultsFolder
    }
}

function Copy-TestResultToTemp {
    <#
     .SYNOPSIS
     Retrieves test results for SonarQube from the current Azure DevOps build and places them in the
     Common Test Results folder ($Agent.TempDirectory)/TestResults
 
     .DESCRIPTION
     Retrieves the test attachments from a build and places them in appropriate locations
     for SonarQube. This method expects the Azure DevOps environment variables to be set
     in order to automatically determine the location and build identity. This method calls
     Copy-TestResult using the appropriate Azure DevOps environment variables.
 
     .EXAMPLE
     Copy-TestResultToTemp
    #>

        [CmdletBinding()]
        param()
        process {
            $buildEnv = Get-BuildEnvironment
            Copy-TestResult -ProjectUri $buildEnv.ProjectUri -AccessToken $buildEnv.AccessToken -BuildUri $buildEnv.BuildUri -OutputFolder $buildEnv.TempTestResultsFolder
        }
}

function Copy-TestResult {
<#
 .SYNOPSIS
 Retrieves test results from a specific Azure DevOps build. If no build details are provided, the current
 build environment is used based on the Azure DevOps environment variables.
 
 .DESCRIPTION
 Retrieves the test attachments from a build and places them in a specified location.
 
 .PARAMETER OutputFolder
 The location for storing the test results. Tests will be organized based on the expected
 folder conventions for SonarQube and the contents of any downloaded TRX files.
 
 .PARAMETER ProjectUri
 The URI to the project root in Azure DevOps.
 
 .PARAMETER AccessToken
 The PAT token or authorization token to use for requesting the build details.
 
 .PARAMETER BuildUri
 The VSTFS URI for the build whose test results should be downloaded.
 
 .PARAMETER TrxDependencyPath
 The format string to use for creating child folders for the TRX file dependencies. The string can utilize a replacement variable, $folder,
 which indicates the folder path for a given dependency (as specified in the TRX file). A second variable, $trxFolder, is the safe folder
 based on the name of the TRX file. The default path is '$trxFolder/In/$folder'. Note that the path string should not be double-quoted
 when the replacement variables are used. All folder paths will be relative to OutputFolder.
 
 .EXAMPLE
 Copy-TestResult -ProjectUri https://dev.azure.com/myorg/project -AccessToken <PAT> -BuildUri vstfs:///Build/Build/1234 -OutputFolder c:\test-results -TrxDependencyPath 'In/$folder'
#>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
        [ValidateNotNullOrEmpty()]
        [string] $OutputFolder,

        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [Uri] $ProjectUri = $script:AzDOBuild.ProjectUri,

        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [string] $AccessToken = $script:AzDOBuild.AccessToken,

        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [string] $BuildUri = $script:AzDOBuild.BuildUri,

        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [string] $TrxDependencyPath = '$trxFolder/In/$folder'
    )

    process {
        $ErrorActionPreference = "Stop"

        # Ensure none of the parameters are $null or empty
        $parameters = @('OutputFolder', 'ProjectUri', 'AccessToken', 'BuildUri')
        foreach ($parameter in $parameters) {
             $value = Get-Variable -Name $parameter -ErrorAction SilentlyContinue;
             if ([string]::IsNullOrWhiteSpace($value.Value)){
                throw [System.ArgumentNullException] $parameter
            }
        }

        $tests = Get-TestRunList -BuildUri $BuildUri -BaseUri $ProjectUri -AccessToken $AccessToken
        if (-Not (Test-Path $OutputFolder)) {
            Write-Verbose "Creating output folder: '$OutputFolder'"
            [void](New-Item -ItemType Directory -Path $OutputFolder -Force)
        }

        foreach ($test in $tests) {
            $content = Get-GroupedAttachmentList -TestUri $test.url -AccessToken $AccessToken

            $trxFiles = $content.TrxContent
            $otherFiles = $content.OtherContent

            if ($trxFiles.Length -gt 0) {
                # Download TRX to get details about any related content locations
                foreach($item in $trxFiles) {
                    Get-TestAttachment -AttachmentUri $item.url -OutputPath "$OutputFolder/$($item.fileName)" -AccessToken $AccessToken
                }

                $trxNodes = Get-TrxContent -Files $trxFiles -OutputFolder $OutputFolder -TrxDependencyPath $TrxDependencyPath
                # Create the required folders for child content
                foreach($node in $trxNodes) {
                    if ($node) {
                        $path = [Path]::GetDirectoryName($node)
                        if ($path) {
                            Write-Verbose "Creating output location: '$path'"
                            [void](New-Item -ItemType Directory -Path $path -Force)
                        }
                    }
                }

                # Download the reamining content
                $simpleFileList = $otherFiles | Select-Object -ExpandProperty 'fileName'
                $childLocations = Group-ChildContent -TrxContentList $trxNodes -FileList $simpleFileList -OutputFolder $OutputFolder
                foreach ($attachment in $otherFiles) {
                    Write-Verbose "Downloading $($attachment.fileName)"
                    $targetLocations = $childLocations[$attachment.FileName]
                    $target = $targetLocations[0]
                    Write-Verbose "Writing $($attachment.fileName) to $target"
                    Get-TestAttachment -AttachmentUri $attachment.url -OutputPath $target -AccessToken $AccessToken

                    if ($targetLocations.Length -gt 1){
                        foreach($dest in $targetLocations | Select-Object -Skip 1 ){
                            Write-Verbose "Writing $($attachment.fileName) to $dest"
                            [void](Copy-Item $target -Destination $dest -Force)
                        }
                    }
                }
            } else {
                Write-Warning "Skipping test run $($test.name) since it does not contain any .trx files"
            }
        }
    }
}

Set-Variable -Name "AzDOBuild" -Value (Get-BuildEnvironment) -Scope script -Option Constant
Export-ModuleMember -Function Copy-TestResult, Copy-TestResultToCommon, Copy-TestResultToTemp
# SIG # Begin signature block
# MIIccwYJKoZIhvcNAQcCoIIcZDCCHGACAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUAO9S7rfop3quRUoI3IM+0Mcb
# xCeggheiMIIFKzCCBBOgAwIBAgIQA92NH6Ao4oJnDDTTKeZ3HzANBgkqhkiG9w0B
# AQsFADByMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYD
# VQQLExB3d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFz
# c3VyZWQgSUQgQ29kZSBTaWduaW5nIENBMB4XDTE5MDkwOTAwMDAwMFoXDTIyMDkx
# MjEyMDAwMFowaDELMAkGA1UEBhMCVVMxEDAOBgNVBAgTB0dlb3JnaWExGTAXBgNV
# BAcTEEF2b25kYWxlIEVzdGF0ZXMxFTATBgNVBAoTDEtlbm5ldGggTXVzZTEVMBMG
# A1UEAxMMS2VubmV0aCBNdXNlMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC
# AQEAsr5Lse8T47fphRV8/FhwMUgYR6h1FrGlf3YLe8nhl6ade5WHAtFZqlguZU+f
# WyP/R5NHf9bKMbHg6IiIuedyBE2fEzCZH5CJwgC3J0Df5qrNf4qI5fBobsryV/mg
# zSOzLBbunPfak1XNTNL0w4ak6jCz8OMAZ9Q+ThHgv5XIO5IhyTqkoMijkeLfg32x
# 5hfYeSQsXDma0yzyd7tGDrhmN+ayhh0nuTYmXS3fjxq8oLztMZhzfRP8Qfvs3SrW
# nZn+tCkGMPawOBc7M3GA5Zvc7yc9OiMprLOFN1BM8aNdGU+xRAQQ6lpO2v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