It was only through the vigilance of MI5 officers who mounted a sting operation where they pretended to be Russian spies that national security was not harmed, said Mark Dennis QC, prosecuting.
Mr Dennis said: "The potential damage could have been considerable and could have harmed the safety and security of the United Kingdom."
Devenney, originally from Northern Ireland, has pleaded guilty to breaching the Official Secrets Act and misconduct in public office.
A submariner has been jailed for eight years for trying to disclose the secret movements of British nuclear submarines to "Russian spies".
Submariner Edward Devenney has admitted collecting top secret naval codes before meeting two men he believed were Russian spies