forked from fescobar/allure-docker-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_results.ps1
59 lines (52 loc) · 2.54 KB
/
send_results.ps1
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
# This directory is where you have all your results locally, generally named as `allure-results`
$ReportPath="allure-results-example"
# This url is where the Allure container is deployed. We are using localhost as example
$BaseUrl = "http://localhost:5050"
# Project ID according to existent projects in your Allure container - Check endpoint for project creation >> `[POST]/projects`
$ProjectId="default"
#$ProjectId="my-project-id"
$Request = @{
"results" = @()
}
$Files = (Get-ChildItem -File -Path "$PSScriptRoot\$ReportPath")
foreach ($Item in $Files) {
$Content = Get-Content -Path $Item.FullName
if ($Content){
$Result = @{
"file_name"= $Item.name
"content_base64"= [Convert]::ToBase64String([IO.File]::ReadAllBytes($Item.FullName))
}
$Request.results += $Result;
}
}
$json = ConvertTo-Json -InputObject $Request
Write-Output "------------------SEND-RESULTS------------------"
$SendResultsEndpoint="$BaseUrl/send-results?project_id=$ProjectId"
$result = Invoke-WebRequest -Uri $SendResultsEndpoint -ContentType 'application/json' -Method POST -Body $json -UseBasicParsing
Write-Output "Status Code:" $result.StatusCode
Write-Output "Response: " $result.Content
<#
#If you want to generate reports on demand use the endpoint `GET /generate-report` and disable the Automatic Execution >> `CHECK_RESULTS_EVERY_SECONDS: NONE`
Write-Output "------------------GENERATE-REPORT------------------"
$ExecutionName ="execution_from_my_ps_script"
$ExecutionFrom ="http://google.com"
$ExecutionType = "bamboo"
$GenerateReportEndpoint="$BaseUrl/generate-report?project_id=$ProjectId"
$response = Invoke-RestMethod -Uri "$GenerateReportEndpoint&execution_name=$ExecutionName&execution_from=$ExecutionFrom&execution_type=$ExecutionType"
$reportUrl = $response.data.report_url
$testreport = @"
_________________________________________________________________________________________________
_____ _ _
|_ _| | | | |
| | ___ ___| |_ _ __ ___ _ __ ___ _ __| |_
| |/ _ \/ __| __| | '__/ _ \ '_ \ / _ \| '__| __|
| | __/\__ \ |_ | | | __/ |_) | (_) | | | |_
\_/\___||___/\__| |_| \___| .__/ \___/|_| \__|
| |
|_|
_________________________________________________________________________________________________
$reportUrl
_________________________________________________________________________________________________
"@
Write-Output $testreport
#>