You’ll need to live in the country where you’re planning to get married for 3 days and then post notice at the British embassy in that country for 7 days. The embassy will issue your CNI if nobody has registered an objection in that time.
If you need an affirmation/affidavit of marital status
In some countries, you’ll need to swear an affirmation or affidavit stating that you’re free to marry. You’ll usually need to do this in front of a consular officer at the British embassy or a local notary public.
There is no residency or notice period, but you should check with the British embassy or consulate in the country where you’re planning to get married if you need to make an appointment.