A man has been spared jail despite beating up his former partner in a "cowardly" attack.