I believe this is a variation of "Here we go!" where you're expecting a negative result, especially if you've nothing to lose you might as well have a punt.
The oldest "here goes nothing" I can find is from 1889's Fibre & Fabric:

"The latest nagging remark; 'Oh, throw yourself In a hole,and say here goes nothing.'"
However, there are earlier variants.
1875's Gulliver's travels into several remote nations of the world has:

"and it would be awkward if I were to step into a hornet's nest. But here goes ; nothing like pluck ! there's always a way out where there's a way in.
And 1885's Blackwood's Edinburgh magazine:

In five minutes I may get my dismissal, and be told to pack my traps. Never mind : here goes — nothing venture, nothing win."