How to write a hook for rerun job based on some exit codes

please help to write a hook to rerun a job if some condition or getting exit code