summaryrefslogtreecommitdiff
path: root/eng/common/templates/steps/telemetry-end.yml
blob: 9cfe3608b8e871e05ed48072c537bf192fdde5d9 (plain)
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
parameters:
  helixSource: 'undefined_defaulted_in_telemetry.yml'
  helixType: 'undefined_defaulted_in_telemetry.yml'

steps:
- bash: |
    if [ "$AGENT_JOBSTATUS" = "Succeeded" ] || [ "$AGENT_JOBSTATUS" = "PartiallySucceeded" ]; then
      errorCount=0
    else
      errorCount=1
    fi
    warningCount=0

    # 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

    if [ $curlStatus -ne 0 ]; then
      echo "Failed to Send Build Finish information"
      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)
  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

    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 }
    }
    catch {
      Write-Error $_
      Write-Error $_.Exception
      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)
  condition: and(always(),eq(variables['Agent.Os'], 'Windows_NT'))