Where does the phrase "It's a good job that ..." come from?

The OED’s definition 5 of job is ‘A state of affairs, a situation, a set of circumstances. Frequently with modifying adjective, as bad, good, etc.’ The earliest citation supporting this definition is from 1690:

'Twas an ill jobb for one Misfortune so soon to fall upon the neck of one another.

The first citation of good job is from Gilbert and Sullivan’s ‘Trial by Jury’ of 1876, which helpfully illustrates both that sense and the sense of ‘a piece of work’:

‘So we've finished with the job, And a good job too!’

The origin of job itself is uncertain, but it is possibly related to the word job meaning 'a cartload; the amount that a horse and cart can bring at one time.'