@@ -45,6 +45,7 @@ public async Task RunAsync(IExecutionContext jobContext, IList<IStep> steps)
45
45
{
46
46
ArgUtil . NotNull ( jobContext , nameof ( jobContext ) ) ;
47
47
ArgUtil . NotNull ( steps , nameof ( steps ) ) ;
48
+ Trace . Entering ( ) ;
48
49
49
50
// TaskResult:
50
51
// Abandoned (Server set this.)
@@ -56,35 +57,48 @@ public async Task RunAsync(IExecutionContext jobContext, IList<IStep> steps)
56
57
CancellationTokenRegistration ? jobCancelRegister = null ;
57
58
int stepIndex = 0 ;
58
59
jobContext . Variables . Agent_JobStatus = jobContext . Result ?? TaskResult . Succeeded ;
60
+ Trace . Info ( $ "Async command completion wait initiated - processing { jobContext . AsyncCommands ? . Count ?? 0 } pending commands") ;
59
61
// Wait till all async commands finish.
62
+ int successfulCommandCount = 0 ;
60
63
foreach ( var command in jobContext . AsyncCommands ?? new List < IAsyncCommandContext > ( ) )
61
64
{
62
65
try
63
66
{
64
67
// wait async command to finish.
68
+ Trace . Info ( $ "Async command initiated [Command:{ command . Name } , CommandType:{ command . GetType ( ) . Name } ]") ;
65
69
await command . WaitAsync ( ) ;
70
+ successfulCommandCount ++ ;
71
+ Trace . Info ( $ "Async command completed successfully: { command . Name } ") ;
66
72
}
67
73
68
74
catch ( Exception ex )
69
75
{
70
76
// Log the error
71
- Trace . Info ( $ "Caught exception from async command { command . Name } : { ex } ") ;
77
+ Trace . Info ( $ "Async command failed during job initialization [Command: { command . Name } , JobId: { jobContext . Variables . System_JobId } , Error: { ex . Message } ] ") ;
72
78
}
73
79
}
80
+ Trace . Info ( $ "Async command completion wait finished - { successfulCommandCount } commands processed") ;
81
+ Trace . Info ( "Step iteration loop initiated - beginning sequential step processing" ) ;
74
82
foreach ( IStep step in steps )
75
83
{
76
- Trace . Info ( $ "Processing step: DisplayName='{ step . DisplayName } ', ContinueOnError={ step . ContinueOnError } , Enabled={ step . Enabled } ") ;
84
+ Trace . Info ( $ "Processing step { stepIndex + 1 } / { steps . Count } : DisplayName='{ step . DisplayName } ', ContinueOnError={ step . ContinueOnError } , Enabled={ step . Enabled } ") ;
77
85
ArgUtil . Equal ( true , step . Enabled , nameof ( step . Enabled ) ) ;
78
86
ArgUtil . NotNull ( step . ExecutionContext , nameof ( step . ExecutionContext ) ) ;
79
87
ArgUtil . NotNull ( step . ExecutionContext . Variables , nameof ( step . ExecutionContext . Variables ) ) ;
80
88
stepIndex ++ ;
81
89
90
+ Trace . Info ( $ "ExecutionContext startup initiated for step: '{ step . DisplayName } '") ;
82
91
// Start.
83
92
step . ExecutionContext . Start ( ) ;
84
93
var taskStep = step as ITaskRunner ;
85
94
if ( taskStep != null )
86
95
{
87
96
HostContext . WritePerfCounter ( $ "TaskStart_{ taskStep . Task . Reference . Name } _{ stepIndex } ") ;
97
+ Trace . Info ( $ "Task step initiated [TaskName:{ taskStep . Task . Reference . Name } , TaskId:{ taskStep . Task . Reference . Id } , Version:{ taskStep . Task . Reference . Version } , Stage:{ taskStep . Stage } ]") ;
98
+ }
99
+ else
100
+ {
101
+ Trace . Info ( $ "Non-task step { step . DisplayName } started [StepType:{ step . GetType ( ) . Name } , Timeout:{ step . Timeout ? . TotalMinutes ?? 0 } min]") ;
88
102
}
89
103
90
104
// Change the current job context to the step context.
@@ -96,6 +110,7 @@ public async Task RunAsync(IExecutionContext jobContext, IList<IStep> steps)
96
110
List < string > expansionWarnings ;
97
111
step . ExecutionContext . Variables . RecalculateExpanded ( out expansionWarnings ) ;
98
112
expansionWarnings ? . ForEach ( x => step . ExecutionContext . Warning ( x ) ) ;
113
+ Trace . Info ( $ "Variable expansion completed [Step:'{ step . DisplayName } ', Warnings:{ expansionWarnings ? . Count ?? 0 } , Target:{ step . Target ? . GetType ( ) ? . Name ?? "None" } ]") ;
99
114
100
115
var expressionManager = HostContext . GetService < IExpressionManager > ( ) ;
101
116
try
@@ -104,9 +119,11 @@ public async Task RunAsync(IExecutionContext jobContext, IList<IStep> steps)
104
119
// Register job cancellation call back only if job cancellation token not been fire before each step run
105
120
if ( ! jobContext . CancellationToken . IsCancellationRequested )
106
121
{
122
+ Trace . Info ( $ "Job cancellation registration setup [Step:'{ step . DisplayName } ', JobCancellationRequested:False, RegistrationActive:True]") ;
107
123
// Test the condition again. The job was canceled after the condition was originally evaluated.
108
124
jobCancelRegister = jobContext . CancellationToken . Register ( ( ) =>
109
125
{
126
+ Trace . Info ( $ "Job cancellation callback triggered [Step:'{ step . DisplayName } ', AgentShutdown:{ HostContext . AgentShutdownToken . IsCancellationRequested } ]") ;
110
127
// mark job as cancelled
111
128
jobContext . Result = TaskResult . Canceled ;
112
129
jobContext . Variables . Agent_JobStatus = jobContext . Result ;
@@ -120,15 +137,19 @@ public async Task RunAsync(IExecutionContext jobContext, IList<IStep> steps)
120
137
PublishTelemetry ( jobContext , TaskResult . Failed . ToString ( ) , "120" ) ;
121
138
jobContext . Result = TaskResult . Failed ;
122
139
jobContext . Variables . Agent_JobStatus = jobContext . Result ;
140
+ Trace . Info ( $ "Agent shutdown failure applied [Step:'{ step . DisplayName } ', FailJobEnabled:True, JobResult:Failed]") ;
123
141
}
124
142
step . ExecutionContext . Debug ( $ "Skip Re-evaluate condition on agent shutdown.") ;
125
143
conditionReTestResult = false ;
144
+ Trace . Info ( $ "Condition re-evaluation skipped [Step:'{ step . DisplayName } ', Reason:AgentShutdown]") ;
126
145
}
127
146
else
128
147
{
129
148
try
130
149
{
150
+ Trace . Info ( $ "Condition re-evaluation initiated [Step:'{ step . DisplayName } ', Expression:'{ step . Condition } ', HostTracingOnly:True]") ;
131
151
conditionReTestResult = expressionManager . Evaluate ( step . ExecutionContext , step . Condition , hostTracingOnly : true ) ;
152
+ Trace . Info ( $ "Condition re-evaluation completed [Step:'{ step . DisplayName } ', Result:{ conditionReTestResult . Value } ]") ;
132
153
}
133
154
catch ( Exception ex )
134
155
{
@@ -142,7 +163,7 @@ public async Task RunAsync(IExecutionContext jobContext, IList<IStep> steps)
142
163
if ( ! conditionReTestResult . Value )
143
164
{
144
165
// Cancel the step.
145
- Trace . Info ( "Cancel current running step. " ) ;
166
+ Trace . Info ( $ "Cancel current running step: { step . DisplayName } ") ;
146
167
step . ExecutionContext . Error ( StringUtil . Loc ( "StepCancelled" ) ) ;
147
168
step . ExecutionContext . CancelToken ( ) ;
148
169
}
@@ -177,12 +198,14 @@ public async Task RunAsync(IExecutionContext jobContext, IList<IStep> steps)
177
198
{
178
199
step . ExecutionContext . Debug ( $ "Skip evaluate condition on agent shutdown.") ;
179
200
conditionResult = false ;
201
+ Trace . Info ( $ "Condition evaluation skipped due to agent shutdown: '{ step . DisplayName } '") ;
180
202
}
181
203
else
182
204
{
183
205
try
184
206
{
185
207
conditionResult = expressionManager . Evaluate ( step . ExecutionContext , step . Condition ) ;
208
+ Trace . Info ( $ "Condition evaluation completed - Result: { conditionResult . Value } , Step: '{ step . DisplayName } '") ;
186
209
}
187
210
catch ( Exception ex )
188
211
{
@@ -198,7 +221,7 @@ public async Task RunAsync(IExecutionContext jobContext, IList<IStep> steps)
198
221
{
199
222
// Condition == false
200
223
string skipStepMessage = "Skipping step due to condition evaluation." ;
201
- Trace . Info ( skipStepMessage ) ;
224
+ Trace . Info ( skipStepMessage + $ "[Step: ' { step . DisplayName } ', Reason:ConditionFalse, Expression:' { step . Condition } ', StepIndex: { stepIndex } / { steps . Count } ]" ) ;
202
225
step . ExecutionContext . Output ( $ "{ skipStepMessage } \n { conditionResult . Trace } ") ;
203
226
step . ExecutionContext . Complete ( TaskResult . Skipped , resultCode : skipStepMessage ) ;
204
227
continue ;
@@ -207,17 +230,21 @@ public async Task RunAsync(IExecutionContext jobContext, IList<IStep> steps)
207
230
if ( conditionEvaluateError != null )
208
231
{
209
232
// fail the step since there is an evaluate error.
233
+ Trace . Error ( $ "Condition evaluation failure context [Step:'{ step . DisplayName } ', Expression:'{ step . Condition } ', StepIndex:{ stepIndex } /{ steps . Count } ]") ;
210
234
step . ExecutionContext . Error ( conditionEvaluateError ) ;
211
235
step . ExecutionContext . Complete ( TaskResult . Failed ) ;
212
236
}
213
237
else
214
238
{
239
+ Trace . Info ( $ "RunStepAsync execution initiated for step: '{ step . DisplayName } '") ;
215
240
// Run the step.
216
241
await RunStepAsync ( step , jobContext . CancellationToken ) ;
242
+ Trace . Info ( $ "RunStepAsync execution completed for step: '{ step . DisplayName } ' - Result: { step . ExecutionContext . Result } ") ;
217
243
}
218
244
}
219
245
finally
220
246
{
247
+ Trace . Info ( $ "Step cancellation registration cleanup [Step:'{ step . DisplayName } ', RegistrationActive:{ jobCancelRegister != null } ]") ;
221
248
if ( jobCancelRegister != null )
222
249
{
223
250
jobCancelRegister ? . Dispose ( ) ;
@@ -229,80 +256,93 @@ public async Task RunAsync(IExecutionContext jobContext, IList<IStep> steps)
229
256
if ( step . ExecutionContext . Result == TaskResult . SucceededWithIssues ||
230
257
step . ExecutionContext . Result == TaskResult . Failed )
231
258
{
232
- Trace . Info ( $ "Update job result with current step result '{ step . ExecutionContext . Result } '. ") ;
259
+ Trace . Info ( $ "Update job result with current step result - Step: '{ step . DisplayName } ', StepResult: { step . ExecutionContext . Result } , PreviousJobResult: { jobContext . Result } ") ;
233
260
jobContext . Result = TaskResultUtil . MergeTaskResults ( jobContext . Result , step . ExecutionContext . Result . Value ) ;
234
261
jobContext . Variables . Agent_JobStatus = jobContext . Result ;
262
+ Trace . Info ( $ "Job result after merge: { jobContext . Result } ") ;
235
263
}
236
264
else
237
265
{
238
- Trace . Info ( $ "No need for updating job result with current step result ' { step . ExecutionContext . Result } '. ") ;
266
+ Trace . Info ( $ "Job result unchanged - Step: ' { step . DisplayName } ', StepResult: { step . ExecutionContext . Result } , JobResultKept: { jobContext . Result } ") ;
239
267
}
240
268
241
269
if ( taskStep != null )
242
270
{
243
271
HostContext . WritePerfCounter ( $ "TaskCompleted_{ taskStep . Task . Reference . Name } _{ stepIndex } ") ;
272
+ Trace . Info ( $ "Task step completion - TaskName:{ taskStep . Task . Reference . Name } , StepIndex:{ stepIndex } /{ steps . Count } , Result: { step . ExecutionContext . Result } , TaskStage:{ taskStep . Stage } ") ;
244
273
}
245
274
246
- Trace . Info ( $ "Current state: job state = '{ jobContext . Result } '") ;
247
275
}
276
+ Trace . Info ( $ "Step iteration loop completed - All { steps . Count } steps processed, Final job result: { jobContext . Result } ") ;
248
277
}
249
278
250
279
private async Task RunStepAsync ( IStep step , CancellationToken jobCancellationToken )
251
280
{
281
+ Trace . Info ( $ "Individual step execution initiated: '{ step . DisplayName } '") ;
252
282
// Start the step.
253
- Trace . Info ( "Starting the step." ) ;
283
+
254
284
step . ExecutionContext . Section ( StringUtil . Loc ( "StepStarting" , step . DisplayName ) ) ;
255
285
step . ExecutionContext . SetTimeout ( timeout : step . Timeout ) ;
256
286
257
287
step . ExecutionContext . Variables . Set ( Constants . Variables . Task . SkipTranslatorForCheckout , Boolean . FalseString ) ;
258
288
289
+ Trace . Info ( $ "UTF-8 codepage switching initiated for step: '{ step . DisplayName } '") ;
259
290
// Windows may not be on the UTF8 codepage; try to fix that
260
291
await SwitchToUtf8Codepage ( step ) ;
292
+ Trace . Info ( $ "UTF-8 codepage switching completed for step: '{ step . DisplayName } '") ;
293
+ // updated code log - Add codepage switching context and platform info
294
+ Trace . Info ( $ "Codepage configuration [Platform:{ ( PlatformUtil . RunningOnWindows ? "Windows" : "Unix" ) } , RetainEncoding:{ step . ExecutionContext . Variables . Retain_Default_Encoding } , CurrentCodepage:{ Console . InputEncoding ? . CodePage } ]") ;
261
295
262
296
try
263
297
{
298
+ Trace . Info ( $ "Step main execution initiated: '{ step . DisplayName } '") ;
264
299
await step . RunAsync ( ) ;
300
+ Trace . Info ( $ "Step main execution completed successfully: '{ step . DisplayName } '") ;
265
301
}
266
302
catch ( OperationCanceledException ex )
267
303
{
268
304
if ( step . ExecutionContext . CancellationToken . IsCancellationRequested &&
269
305
! jobCancellationToken . IsCancellationRequested )
270
306
{
271
- Trace . Error ( $ "Caught timeout exception from step: { ex . Message } ") ;
307
+ Trace . Error ( $ "Caught timeout exception from step: Step: { step . DisplayName } , Exception: { ex . Message } , ConfiguredTimeout: { step . Timeout ? . TotalMinutes ?? 0 } min ") ;
272
308
step . ExecutionContext . Error ( StringUtil . Loc ( "StepTimedOut" ) ) ;
273
309
step . ExecutionContext . Result = TaskResult . Failed ;
274
310
}
275
311
else if ( AgentKnobs . FailJobWhenAgentDies . GetValue ( step . ExecutionContext ) . AsBoolean ( ) &&
276
312
HostContext . AgentShutdownToken . IsCancellationRequested )
277
313
{
278
314
PublishTelemetry ( step . ExecutionContext , TaskResult . Failed . ToString ( ) , "122" ) ;
279
- Trace . Error ( $ "Caught Agent Shutdown exception from step: { ex . Message } ") ;
315
+ Trace . Error ( $ "Caught Agent Shutdown exception from step: Step:' { step . DisplayName } ', ShutdownReason: { HostContext . AgentShutdownReason } , Exception: { ex . Message } ") ;
280
316
step . ExecutionContext . Error ( ex ) ;
281
317
step . ExecutionContext . Result = TaskResult . Failed ;
282
318
}
283
319
else
284
320
{
285
321
// Log the exception and cancel the step.
286
- Trace . Error ( $ "Caught cancellation exception from step: { ex } ") ;
322
+ Trace . Error ( $ "Caught cancellation exception from step: Step: { step . DisplayName } , CancellationSource:JobLevel, JobCancelled: { jobCancellationToken . IsCancellationRequested } ") ;
287
323
step . ExecutionContext . Error ( ex ) ;
288
324
step . ExecutionContext . Result = TaskResult . Canceled ;
289
325
}
290
326
}
291
327
catch ( Exception ex )
292
328
{
329
+ Trace . Error ( $ "Caught exception from step: - Step: '{ step . DisplayName } ', Exception: { ex } ") ;
293
330
// Log the error and fail the step.
294
- Trace . Error ( $ "Caught exception from step: { ex } ") ;
295
331
step . ExecutionContext . Error ( ex ) ;
296
332
step . ExecutionContext . Result = TaskResult . Failed ;
297
333
}
298
334
335
+ Trace . Info ( $ "Async command completion wait initiated for step: '{ step . DisplayName } ' - Commands: { step . ExecutionContext . AsyncCommands ? . Count ?? 0 } ") ;
299
336
// Wait till all async commands finish.
300
337
foreach ( var command in step . ExecutionContext . AsyncCommands ?? new List < IAsyncCommandContext > ( ) )
301
338
{
302
339
try
303
340
{
304
341
// wait async command to finish.
342
+ // check this - add log to mark start of this call as well, also add required meatadata to log for it
343
+ Trace . Info ( $ "Step async command initiated [Command:{ command . Name } , Step:'{ step . DisplayName } ', CommandType:{ command . GetType ( ) . Name } ]") ;
305
344
await command . WaitAsync ( ) ;
345
+ Trace . Info ( $ "Step async command completion [Command:{ command . Name } ]") ;
306
346
}
307
347
catch ( OperationCanceledException ex )
308
348
{
@@ -346,27 +386,30 @@ private async Task RunStepAsync(IStep step, CancellationToken jobCancellationTok
346
386
step . ExecutionContext . CommandResult = TaskResultUtil . MergeTaskResults ( step . ExecutionContext . CommandResult , TaskResult . Failed ) ;
347
387
}
348
388
}
389
+ Trace . Info ( $ "Step async command summary [Step:'{ step . DisplayName } ', TotalCommands:{ step . ExecutionContext . AsyncCommands ? . Count ?? 0 } , CommandResult:{ step . ExecutionContext . CommandResult } ]") ;
349
390
350
391
// Merge executioncontext result with command result
351
392
if ( step . ExecutionContext . CommandResult != null )
352
393
{
353
394
step . ExecutionContext . Result = TaskResultUtil . MergeTaskResults ( step . ExecutionContext . Result , step . ExecutionContext . CommandResult . Value ) ;
395
+ Trace . Info ( $ "Step result merged with command result - Step: { step . DisplayName } , CommandResult:{ step . ExecutionContext . CommandResult } FinalResult: { step . ExecutionContext . Result } ") ;
354
396
}
355
397
356
- // Fixup the step result if ContinueOnError.
398
+ // Fixup the step result if ContinueOnError.
357
399
if ( step . ExecutionContext . Result == TaskResult . Failed && step . ContinueOnError )
358
400
{
359
401
step . ExecutionContext . Result = TaskResult . SucceededWithIssues ;
360
- Trace . Info ( $ "Updated step result: { step . ExecutionContext . Result } ") ;
402
+ Trace . Info ( $ "Step result updated due to ContinueOnError: ' { step . DisplayName } ', Result: Failed -> SucceededWithIssues ") ;
361
403
}
362
404
else
363
405
{
364
- Trace . Info ( $ "Step result: { step . ExecutionContext . Result } ") ;
406
+ Trace . Info ( $ "Step result: ' { step . DisplayName } ', Result: { step . ExecutionContext . Result } ") ;
365
407
}
366
408
367
409
// Complete the step context.
368
410
step . ExecutionContext . Section ( StringUtil . Loc ( "StepFinishing" , step . DisplayName ) ) ;
369
411
step . ExecutionContext . Complete ( ) ;
412
+ Trace . Info ( $ "Step execution summary - Step: '{ step . DisplayName } ', FinalResult: { step . ExecutionContext . Result } ") ;
370
413
}
371
414
372
415
private async Task SwitchToUtf8Codepage ( IStep step )
0 commit comments