abort throws an exception, which would normally end script execution. It can take an optional message which DeployHub will issue when the script ends.


abort is typically used when a condition arises that would prevent 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.


Since abort throws an exception it can be caught with a try/catch block. This allows you to 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