He joined the Royal Navy in the 1770s and served off the Eastern Seaboard of North America during the American War of Independence, seeing action at the Siege of Charleston.
During the peace of 1783 to 1793, Donnelly joined the fleet of the Honourable East India Company, serving as a mate before rejoining the Navy at the outbreak of the French Revolutionary Wars.
In June 1795, Donnelly was promoted to post captain and took command of the frigate HMS Pegasus, serving with the North Sea Fleet and participating in the action of 12 May 1796 off the Dutch coast.
From there he joined the Mediterranean Fleet where Admiral Lord Nelson would later hold him in high esteem, commending him in letters and placing several of his proteges under Donnelly's command.
In 1805, he accompanied the expeditionary force which invaded the Cape of Good Hope and the Rio de la Plata, where he was commended and rewarded on his return to Britain with command of the ship of the line HMS Ardent which he brought back to South America and continued serving in the campaign until its conclusion in 1807.
By July 1840, a lunacy commission was held to inquire into the admiral's state of mind, which heard from witnesses who testified that Donnelly was forgetful, confused, and prone to fits of abuse directed at his staff, several of whom he dismissed only to mistake them for new servants when they returned.