2019-02-02 13:41:24 +00:00
|
|
|
parameters:
|
|
|
|
maxRetries: 5
|
|
|
|
retryDelay: 10 # in seconds
|
|
|
|
|
2018-10-17 22:17:40 +00:00
|
|
|
steps:
|
|
|
|
- bash: |
|
|
|
|
if [ "$AGENT_JOBSTATUS" = "Succeeded" ] || [ "$AGENT_JOBSTATUS" = "PartiallySucceeded" ]; then
|
|
|
|
errorCount=0
|
|
|
|
else
|
|
|
|
errorCount=1
|
|
|
|
fi
|
|
|
|
warningCount=0
|
|
|
|
|
2019-02-02 13:41:24 +00:00
|
|
|
curlStatus=1
|
|
|
|
retryCount=0
|
|
|
|
# retry loop to harden against spotty telemetry connections
|
|
|
|
# we don't retry successes and 4xx client errors
|
|
|
|
until [[ $curlStatus -eq 0 || ( $curlStatus -ge 400 && $curlStatus -le 499 ) || $retryCount -ge $MaxRetries ]]
|
|
|
|
do
|
|
|
|
if [ $retryCount -gt 0 ]; then
|
|
|
|
echo "Failed to send telemetry to Helix; waiting $RetryDelay seconds before retrying..."
|
|
|
|
sleep $RetryDelay
|
2018-10-17 22:17:40 +00:00
|
|
|
fi
|
2019-02-02 13:41:24 +00:00
|
|
|
|
|
|
|
# create a temporary file for curl output
|
|
|
|
res=`mktemp`
|
|
|
|
|
|
|
|
curlResult=`
|
|
|
|
curl --verbose --output $res --write-out "%{http_code}"\
|
|
|
|
-H 'Content-Type: application/json' \
|
|
|
|
-H "X-Helix-Job-Token: $Helix_JobToken" \
|
|
|
|
-H 'Content-Length: 0' \
|
|
|
|
-X POST -G "https://helix.dot.net/api/2018-03-14/telemetry/job/build/$Helix_WorkItemId/finish" \
|
|
|
|
--data-urlencode "errorCount=$errorCount" \
|
|
|
|
--data-urlencode "warningCount=$warningCount"`
|
|
|
|
curlStatus=$?
|
|
|
|
|
|
|
|
if [ $curlStatus -eq 0 ]; then
|
|
|
|
if [ $curlResult -gt 299 ] || [ $curlResult -lt 200 ]; then
|
|
|
|
curlStatus=$curlResult
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
let retryCount++
|
|
|
|
done
|
2018-10-17 22:17:40 +00:00
|
|
|
|
|
|
|
if [ $curlStatus -ne 0 ]; then
|
2019-02-02 13:41:24 +00:00
|
|
|
echo "Failed to Send Build Finish information after $retryCount retries"
|
2018-10-17 22:17:40 +00:00
|
|
|
vstsLogOutput="vso[task.logissue type=error;sourcepath=templates/steps/telemetry-end.yml;code=1;]Failed to Send Build Finish information: $curlStatus"
|
|
|
|
echo "##$vstsLogOutput"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
displayName: Send Unix Build End Telemetry
|
|
|
|
env:
|
|
|
|
# defined via VSTS variables in start-job.sh
|
|
|
|
Helix_JobToken: $(Helix_JobToken)
|
|
|
|
Helix_WorkItemId: $(Helix_WorkItemId)
|
2019-02-02 13:41:24 +00:00
|
|
|
MaxRetries: ${{ parameters.maxRetries }}
|
|
|
|
RetryDelay: ${{ parameters.retryDelay }}
|
2018-10-17 22:17:40 +00:00
|
|
|
condition: and(always(), ne(variables['Agent.Os'], 'Windows_NT'))
|
|
|
|
- powershell: |
|
|
|
|
if (($env:Agent_JobStatus -eq 'Succeeded') -or ($env:Agent_JobStatus -eq 'PartiallySucceeded')) {
|
|
|
|
$ErrorCount = 0
|
|
|
|
} else {
|
|
|
|
$ErrorCount = 1
|
|
|
|
}
|
|
|
|
$WarningCount = 0
|
|
|
|
|
2019-02-02 13:41:24 +00:00
|
|
|
# Basic retry loop to harden against server flakiness
|
|
|
|
$retryCount = 0
|
|
|
|
while ($retryCount -lt $env:MaxRetries) {
|
|
|
|
try {
|
|
|
|
Invoke-RestMethod -Uri "https://helix.dot.net/api/2018-03-14/telemetry/job/build/$env:Helix_WorkItemId/finish?errorCount=$ErrorCount&warningCount=$WarningCount" -Method Post -ContentType "application/json" -Body "" `
|
|
|
|
-Headers @{ 'X-Helix-Job-Token'=$env:Helix_JobToken }
|
|
|
|
break
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
$statusCode = $_.Exception.Response.StatusCode.value__
|
|
|
|
if ($statusCode -ge 400 -and $statusCode -le 499) {
|
|
|
|
Write-Host "##vso[task.logissue]error Failed to send telemetry to Helix (status code $statusCode); not retrying (4xx client error)"
|
|
|
|
Write-Host "##vso[task.logissue]error ", $_.Exception.GetType().FullName, $_.Exception.Message
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
Write-Host "Failed to send telemetry to Helix (status code $statusCode); waiting $env:RetryDelay seconds before retrying..."
|
|
|
|
$retryCount++
|
|
|
|
sleep $env:RetryDelay
|
|
|
|
continue
|
|
|
|
}
|
2018-10-17 22:17:40 +00:00
|
|
|
}
|
2019-02-02 13:41:24 +00:00
|
|
|
|
|
|
|
if ($retryCount -ge $env:MaxRetries) {
|
|
|
|
Write-Host "##vso[task.logissue]error Failed to send telemetry to Helix after $retryCount retries."
|
2018-10-17 22:17:40 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
displayName: Send Windows Build End Telemetry
|
|
|
|
env:
|
|
|
|
# defined via VSTS variables in start-job.ps1
|
|
|
|
Helix_JobToken: $(Helix_JobToken)
|
|
|
|
Helix_WorkItemId: $(Helix_WorkItemId)
|
2019-02-02 13:41:24 +00:00
|
|
|
MaxRetries: ${{ parameters.maxRetries }}
|
|
|
|
RetryDelay: ${{ parameters.retryDelay }}
|
2018-10-17 22:17:40 +00:00
|
|
|
condition: and(always(),eq(variables['Agent.Os'], 'Windows_NT'))
|