This effect is due to the different ways that certain drugs interact with the micturition pathway and thus cause urinary retention.
It is associated with drugs that have anticholinergic activity (e.g. antipsychotic drugs, antidepressant agents and anticholinergic respiratory agents), opioids and anaesthetics, alpha-adrenoceptor agonists, benzodiazepines, NSAIDs, detrusor relaxants and calcium channel antagonists.
I take opioids on a regular basis for chronic pain so I know how you feel. Try over the counter diuretics or talk to your doctor for other prescription options.