In indeed you have noticed that whenever you are exposed to cigarette smoke this persistently and invariably precipitates a headache or migraine attack, then the answer is pretty obvious: you need to avoid such exposure. As for the treatment, it depends on the type of headache you have - you are therefore encouraged to visit your physician to identify the specific type of headache you suffer from (tension headache versus migraine, which are the most common types), and prescribe the correct treatment accordingly.