He joined the Royal Navy in the 1770s and served off the Eastern Seaboard of North America during the French Revolutionary Wars, seeing action at the Siege of Charleston. He was subsequently transferred to Newfoundland and given command of the sloop HMS Morning Star for the remainder of the war. 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.
Donnelly was assigned to the 74 gun ship of the line HMS Montagu under Captain James Montagu and served in the Channel Fleet, joining the fleet under Lord Howe that participated in the Atlantic campaign of May 1794 and fought at the Glorious First of June.
Montagu was heavily engaged and Captain Montagu was killed in the early stages, command devolving on Donnelly. Donnelly commanded the ship with skill and was commended, but due to his rank was denied the rewards that went to the victorious captains.
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. Donnelly later took command of HMS Maidstone and in 1801 escorted a convoy from Porto to Britain before taking command of the frigate HMS Narcissus in the Mediterranean Fleet where Admiral Lord Nelson had a high opinion of him.
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.
In 1808 he took command of HMS Invincible, but was forced into early retirement in 1810 due to cataracts. His eyesight slowly recovered over the next two years, and at the end of the war he was on the verge of commissioning the new ship of the line HMS Devonshire. Postwar, Donnelly retired, although he remained in service and received steady promotions, becoming a full admiral in 1838.
A year earlier he had been rewarded for his long service with a knighthood, becoming a Knight Commander of the Order of the Bath.
He died on 30 September 1840. He is buried in the overgrown north-west quadrant of the inner circle at Kensal Green Cemetery in London.