Does drinking alcohol before a semen analysis ok?

No. because it impairs sperm structure and function, and may well be the reason that you and your partner are experiencing fertility issues. Anytime someone asks me if drinking before or after activity X, or drug Y (or whatever), I am concerned that drinking is too important a focus in your life, which is one step on the road to an alcohol problem. Be honest with your doctor about it.
Generally OK. There are some studies showing that alcohol and caffeine do not affect sperm count or motility. It is generally not part of the pretest instructions to abstain from alcohol. No sex for 3-5 days before the test is best, if alcohol encourages you to be sexually active, then it may be best to not drink.