This thesis investigates the conditions under which rainfall variability affects violent, state-based conflict. More than a decade of research on the climate-conflict nexus has produced diverse results, which could imply that the link is context specific. Yet, the literature on the nexus has focused excessively on finding one effect that applies to all contexts, and has blamed the divergent results on differences in research design, even though the effect is likely to vary. To address this research gap, this thesis studies how the effect of rainfall variability on violent, state-based conflict varies depending on different factors of vulnerability. The effect of rainfall on conflict is hypothesized to be larger the more vulnerable a community is to rainfall shocks and conflict. The thesis uses a new machine learning method for causal inference called causal forest, and applies it on global data from 1989-2018. As such, the thesis offers a new methodological approach to studying the climate-conflict nexus. Excess and scarce rainfall are operationalized through the Standardized Precipitation and Evapotranspiration Index (SPEI) and violent, state-based conflict is derived from the Uppsala Conflict Data Program (UCDP). The results show that excess and scarce rainfall have small effects on conflict in all contexts, but that some types of vulnerability, such as having large parts of a population employed within the agricultural sector, makes that effect larger. The results of the thesis emphasize the need for more research that studies the context specificity of the climate-conflict link. Estimates of an average effect of climate variability on conflict is of little interest if the true effect differs from context to context.