It means that if things end up okay, then the whole thing is okay.
"All's Well That Ends Well" is the title of a play by William Shakespeare.
This play concerns a maid, Helena, who cures the King of France of a disease, then asks for Lord Bertram's hand in marriage. Bertram obliges, then quickly flees to Italy to engage in war, hoping for...
William Shakespeare
Thomson and Thompson