Abort
Using abort to end a script execution.
abort throws an exception, which would normally end a script execution. It can take an optional message which DeployHub Pro will issue when the script ends. abort is typically used when a condition prevents the rest of the script from executing correctly. abort takes a single, named parameter:
msg: The message to print on abort. If msg is not specified, the msg defaults to ABORT.
It can be caught with a try/catch block so you can break out of a block of code whilst still allowing the script to execute.
Example
abort(msg: "Something went wrong");
This will end the script with the message "Something went wrong".
abort;
This will end the script with the message "ABORT"
try {
echo "About to abort";
abort(msg: "Custom Message");
echo "This will never execute";
} catch (ex) {
echo "Error: $ex";
}
echo "Carry on";
Result:
About to abort
Error: Custom Message
Carry on
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.
Last modified September 18, 2024: Signed-off-by: tracyragan <[email protected]> (7195cf1)