Hi @Le Thinh - Munich-MR , Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.
Please find below possible solutions.
- Capture the final result to a variable (recommended when only final output needed)
- Inside the
Untilloop, when you detect the task iscompleted, set a variablefinalExitCodeand (optionally)finalOutputfrom theGet Azure Batch job taskaction, thenTerminate/exit the loop. - Example set-variable expression:
setVariable('finalExitCode', outputs('Get_Azure_Batch_job_task')?['body/executionInfo/exitCode']) - Outside the loop use
variables('finalExitCode')in your IF.
- Inside the
- Move the “Get task output” action outside the loop (clean separation)
- Let the loop only poll for status. Once the loop finishes (status == completed), call
Get Azure Batch job task outputonce, then use its outputs in the IF. - This ensures the output action is in the parent scope and its outputs are directly visible to downstream actions.
- Let the loop only poll for status. Once the loop finishes (status == completed), call
- Collect every iteration’s outputs if you need full history
- Initialize an array variable
iterationResults = []. Inside the loop append a small object each iteration: e.g.,appendToArray('iterationResults', { iteration: variables('i'), state: body(...).state, exitCode: body(...).executionInfo.exitCode, timestamp: utcNow() }). - After the loop you’ll have every iteration’s payloads in
variables('iterationResults')to inspect, store, or branch on.
- Initialize an array variable
Please do let me know if any further question on this or do let me know if it works.