Gary Rough used the vegetable as a weapon when he demanded cash at the Ladbrokes betting shop in Shettleston, Glasgow, last December.
His plan was foiled by a brave shopworker - and by a police officer who happened to be in the bookie's at the time.
The female worker refused to hand over money before the off-duty detective stepped in and pinned 28-year-old Rough to the ground.
Rough later told police who arrested him that the 'weapon' he was wielding was in fact a cucumber.
He asked them: "Am I getting the jail for this?"
Rough is now behind bars after he admitted a charge of assault with intent to rob at the High Court in Glasgow.
Lord Bannatyne locked him up for three years and four months for what he said remained a "nasty crime".
The court heard how the bookmakers was busy when Rough carried out the raid at around 1pm on December 18 last year.
Prosecutor Sheena Fraser said Rough was armed with a "long cylindrical object covered in a black sock" when he went to the counter for cash.
Worker Andrea McIntosh thought it may be a gun but refused to give him money.
The court heard Detective Sergeant Drew White also happened to be in the betting shop and heard the commotion.
CCTV showed DS White knocking Rough to the ground with one blow.
The black sock was then taken off the "weapon" revealing it to be a cucumber.
Rough initially told police it was "a joke" adding: "It was a dare.
"Am I getting the jail for this?"
He later added: "I think it was quite stupid.
"I am not a robber.
"It was a laugh that went too far.
"I hold my hands up."
Tony Graham, defending, said Rough was a £500-a-week plumber who "could give no explanation" why he tried to rob the bookmakers.
Mr Graham added: "He is a man who had no outstanding issues that would need him to seek financial gain from a robbery.
"While he was aware that it was a vegetable in a sock, he is also aware it may have appeared different to others."