How to detect ant retrieve failure in script?

Question

Is there a way to detect if an ant retrieve call fails due to a login issue?

Background

I’ve got a pretty basic bash script that uses ant to retrieve the latest changes from our production instance and commit them to a git repo. In order to get track deletions I have to first clear out the src folder since retrieve leaves deleted components behind. Problem is if their is any failure with the retrieve call it commits with an empty folder. How can I get my script to exit if the retrieve call fails?

Answer

There are two ways you can control this:

1) You can check the error code from the ant run. If the error code is not 0, there was an error. For example, something like this should work (*nix):

ant retrieve
if [ "$?" = "0" ]; then
    # commit;
else 
    echo "Failed to retrieve, skipping commit.";
fi

2) You can commit in the ant target directly using the ant exec command; if the retrieve fails, the commit will never occur.

Attribution
Source : Link , Question Author : Ralph Callaway , Answer Author : sfdcfox

Leave a Comment