Is there a command from script that will stop a build or break from a list iterator loop? I have a list iterator and wanted to put into the AfterAction of the last action to eithr exit the build or break from the iteration loop (either would be fine) if a certain variable is set to true. Or is there maybe a better way to do that?
Well, I just found the continue parameter to the AfterAction which appears to stop the build if set to false. That should work in this case, but I am still curious if there is just a way to break from an iteration loop but continue with the build with the next action after the iteration loop?
Actually I have run into a problem trying to set the Continue parameter to false.
If I add the following statement only to the AfterAction of a “Build Delphi Win32” action:
Continue = false;
The following error pops up:
“No action with error status found”
This Delphi Build action is the last action in a List Iterator loop.
If I set a break point on that line of code, it still errors out instead of stopping at the breakpoint. It appears to get through the Delphi Build according to the log. If I remove that line of code it works just fine.
You can use the Exit loop action to break from a loop and continue to on to the next action immediately after the loop.
A far as stopping a build from a script event, in the AfterAction event you need to set the ActionResult to false and Continue to false. Setting both these properties to false will stop and fail the action. If you set ActionResult to false without setting continue to false then the action result will be ‘Error Ignored’ and the build script will continue.
You can only set the Continue property to false if the action has failed or the ActionResult property has already been set to false.
Thanks Steve, the ExitLoop action is exactly what I was looking for. But now I am having difficulties with that. It may just be that I am not using Execute Condition correctly. It seems to work correctly when I want it to exit the loop (when the execute condition is true) but when the execute condition is false, the status says "skipped" but the loop still exits. The List Iterator does not process the second item in the list. Any idea what I might be doing wrong?
While an iterator loops, it is not really a loop, so the exit loop action does not work. I realized all I have to do is set the execute condition for the list iterator action. So when control comes back to the iterator action for the next item, the execute action will end the loop if the variable is set correctly.
It turns out there was a bug in the Exit Loop action that meant that the loop would exit even if the Execute Condition did not evaluate to true. We have fixed this issue in the latest build.