Welcome to mirror list, hosted at ThFree Co, Russian Federation.

telemetry-start.yml « steps « templates « common « eng - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 32c01ef0b553b44f545db2740aaef0ab2f67350c (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
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
parameters:
  helixSource: 'undefined_defaulted_in_telemetry.yml'
  helixType: 'undefined_defaulted_in_telemetry.yml'
  buildConfig: ''
  runAsPublic: false
  maxRetries: 5
  retryDelay: 10 # in seconds

steps:
- ${{ if and(eq(parameters.runAsPublic, 'false'), not(eq(variables['System.TeamProject'], 'public'))) }}:
  - task: AzureKeyVault@1
    inputs:
      azureSubscription: 'HelixProd_KeyVault'
      KeyVaultName: HelixProdKV
      SecretsFilter: 'HelixApiAccessToken'
    condition: always()
- bash: |
    # create a temporary file
    jobInfo=`mktemp`

    # write job info content to temporary file
    cat > $jobInfo <<JobListStuff
    {
      "QueueId": "$QueueId",
      "Source": "$Source",
      "Type": "$Type",
      "Build": "$Build",
      "Attempt": "$Attempt",
      "Properties": {
        "operatingSystem": "$OperatingSystem",
        "configuration": "$Configuration"
      }
    }
    JobListStuff

    cat $jobInfo

    # create a temporary file for curl output
    res=`mktemp`

    accessTokenParameter="?access_token=$HelixApiAccessToken"

    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
      fi

      curlResult=`
        cat $jobInfo |\
        curl --trace - --verbose --output $res --write-out "%{http_code}" \
        -H 'Content-Type: application/json' \
        -X POST "https://helix.dot.net/api/2018-03-14/telemetry/job$accessTokenParameter" -d @-`
      curlStatus=$?

      if [ $curlStatus -eq 0 ]; then
        if [ $curlResult -gt 299 ] || [ $curlResult -lt 200 ]; then
          curlStatus=$curlResult
        fi
      fi

      let retryCount++
    done

    curlResult=`cat $res`

    # validate status of curl command
    if [ $curlStatus -ne 0 ]; then
      echo "Failed To Send Job Start information after $retryCount retries"
      # We have to append the ## vso prefix or vso will pick up the command when it dumps the inline script into the shell
      vstsLogOutput="vso[task.logissue type=error;sourcepath=telemetry/start-job.sh;code=1;]Failed to Send Job Start information: $curlStatus"
      echo "##$vstsLogOutput"
      exit 1
    fi

    # Set the Helix_JobToken variable
    export Helix_JobToken=`echo $curlResult | xargs echo` # Strip Quotes
    echo "##vso[task.setvariable variable=Helix_JobToken;issecret=true;]$Helix_JobToken"
  displayName: Send Unix Job Start Telemetry
  env:
    HelixApiAccessToken: $(HelixApiAccessToken)
    Source: ${{ parameters.helixSource }}
    Type: ${{ parameters.helixType }}
    Build: $(Build.BuildNumber)
    QueueId: $(Agent.Os)
    Attempt: 1
    OperatingSystem: $(Agent.Os)
    Configuration: ${{ parameters.buildConfig }}
    MaxRetries: ${{ parameters.maxRetries }}
    RetryDelay: ${{ parameters.retryDelay }}
  condition: and(always(), ne(variables['Agent.Os'], 'Windows_NT'))
- bash: |
    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
      fi

      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" \
        --data-urlencode "buildUri=$BuildUri"`
      curlStatus=$?

      if [ $curlStatus -eq 0 ]; then
        if [ $curlResult -gt 299 ] || [ $curlResult -lt 200 ]; then
          curlStatus=$curlResult
        fi
      fi

      curlResult=`cat $res`
      let retryCount++
    done

    # validate status of curl command
    if [ $curlStatus -ne 0 ]; then
      echo "Failed to Send Build Start information after $retryCount retries"
      vstsLogOutput="vso[task.logissue type=error;sourcepath=telemetry/build/start.sh;code=1;]Failed to Send Build Start information: $curlStatus"
      echo "##$vstsLogOutput"
      exit 1
    fi

    export Helix_WorkItemId=`echo $curlResult | xargs echo` # Strip Quotes
    echo "##vso[task.setvariable variable=Helix_WorkItemId]$Helix_WorkItemId"
  displayName: Send Unix Build Start Telemetry
  env:
    BuildUri: $(System.TaskDefinitionsUri)$(System.TeamProject)/_build/index?buildId=$(Build.BuildId)&_a=summary
    Helix_JobToken: $(Helix_JobToken)
    MaxRetries: ${{ parameters.maxRetries }}
    RetryDelay: ${{ parameters.retryDelay }}
  condition: and(always(), ne(variables['Agent.Os'], 'Windows_NT'))

- powershell: |
    $jobInfo = [pscustomobject]@{
      QueueId=$env:QueueId;
      Source=$env:Source;
      Type=$env:Type;
      Build=$env:Build;
      Attempt=$env:Attempt;
      Properties=[pscustomobject]@{ operatingSystem=$env:OperatingSystem; configuration=$env:Configuration };
    }

    $jobInfoJson = $jobInfo | ConvertTo-Json

    if ($env:HelixApiAccessToken) {
      $accessTokenParameter="?access_token=$($env:HelixApiAccessToken)"
    }
    Write-Host "Job Info: $jobInfoJson"

    # Basic retry loop to harden against server flakiness
    $retryCount = 0
    while ($retryCount -lt $env:MaxRetries) {
      try {
        $jobToken = Invoke-RestMethod -Uri "https://helix.dot.net/api/2018-03-14/telemetry/job$($accessTokenParameter)" -Method Post -ContentType "application/json" -Body $jobInfoJson
        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
      }
    }

    if ($retryCount -ge $env:MaxRetries) {
      Write-Host "##vso[task.logissue]error Failed to send telemetry to Helix after $retryCount retries."
      exit 1
    }

    $env:Helix_JobToken = $jobToken
    Write-Host "##vso[task.setvariable variable=Helix_JobToken;issecret=true;]$env:Helix_JobToken"
  env:
    HelixApiAccessToken: $(HelixApiAccessToken)
    Source: ${{ parameters.helixSource }}
    Type: ${{ parameters.helixType }}
    Build: $(Build.BuildNumber)
    QueueId: $(Agent.Os)
    Attempt: 1
    OperatingSystem: $(Agent.Os)
    Configuration: ${{ parameters.buildConfig }}
    MaxRetries: ${{ parameters.maxRetries }}
    RetryDelay: ${{ parameters.retryDelay }}
  condition: and(always(), eq(variables['Agent.Os'], 'Windows_NT'))
  displayName: Send Windows Job Start Telemetry
- powershell: |
    # Basic retry loop to harden against server flakiness
    $retryCount = 0
    while ($retryCount -lt $env:MaxRetries) {
      try {
        $workItemId = Invoke-RestMethod -Uri "https://helix.dot.net/api/2018-03-14/telemetry/job/build?buildUri=$([Net.WebUtility]::UrlEncode($env:BuildUri))" -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
      }
    }

    if ($retryCount -ge $env:MaxRetries) {
      Write-Host "##vso[task.logissue]error Failed to send telemetry to Helix after $retryCount retries."
      exit 1
    }

    $env:Helix_WorkItemId = $workItemId
    Write-Host "##vso[task.setvariable variable=Helix_WorkItemId]$env:Helix_WorkItemId"
  displayName: Send Windows Build Start Telemetry
  env:
    BuildUri: $(System.TaskDefinitionsUri)$(System.TeamProject)/_build/index?buildId=$(Build.BuildId)&_a=summary
    Helix_JobToken: $(Helix_JobToken)
    MaxRetries: ${{ parameters.maxRetries }}
    RetryDelay: ${{ parameters.retryDelay }}
  condition: and(always(), eq(variables['Agent.Os'], 'Windows_NT'))