Mark Cutler produced the hand gun outside the home of his ex’s new partner after learning of their relationship.
Cutler was originally warned he faced an “extremely long sentence” unless he co-operated with police to track down the gun that was used in the incident.
The weapon has still not been recovered but prosecutor Phil Howes said that Cutler had given what assistance he could although the gun has still not been traced.
Cutler, 24, of Harpswell Close, Gainsborough, admitted possession of an imitation firearm with intent to cause fear on 18th January.
He also admitted harassment.
In addition to being jailed he was given an indefinite restraining order preventing him from contacting victim Jordan Bullivant and banned from entering Linden Terrace in Gainsborough.
Judge Sean Morris told him: “When your girlfriend dumped you, you behaved like a spoiled child. Everybody at some time in their lives gets dumped. They have to live with it.”
Mr Howes told the court that Cutler followed his teenage ex and Mr Bullivant around Gainsborough at one point pulling a knife from his pocket only to be calmed down by the 18-year-old girl.
Then in the early hours Cutler went to the home of the new partner in Linden Terrace and after knocking on the door shouted: “Get him out of here”.
Mr Howes said Cutler was ushered away but then produced the handgun and pointed it towards a window aiming it directly at the man inside the house.
“He then pointed it up into the sky with both hands and fired it.”
“The police were informed and the defendant was arrested the following day.”
Mr Howes said the weapon is thought to have been an imitation hand gun.
Following his arrest he admitted harassing his ex and confessed to producing the knife and making threats to harm the new boyfriend.