Climate models predict an increase in rainfall variability, higher frequency of extreme water events, and deeper water scarcity over the coming decades. These changes could have profound impacts on the global agricultural sector. In this paper, we explore how rainfall variability impacts agricultural production along two margins: the intensity of output (yields) and the extensiveness of production, and how water infrastructure influences this relationship. Using global, gridded datasets on net primary productivity (NPP), land cover, and weather, we find that, on average, contemporaneous wet shocks tend to increase agricultural productivity. Contemporaneous dry shocks decrease crop productivity, while repeated dry shocks also tend to increase the rate of cropland expansion, perhaps as an adaptation technique to compensate for lower yields. We argue that the theoretical underpinnings for these results can be found in the "safety-first" model, where the priority of the economic agent is to generate a threshold level of income or output. Further, using an instrumental variables based identification strategy for dam construction, we find that the buffering impact of upstream irrigation dams varies by geography, climate, and income levels. Upstream dams, in general, decrease the extent of cropland expansion to persistent dry shocks across different climatic zones and income levels, yet in developing countries with arid climates, they appear to accentuate the adverse effects of dry shocks on agricultural productivity. One possible reason for this relationship which we find evidence for is mal-adaptation, where the presence of dams incentivize farmers to plant waterintensive crops in otherwise unsuitable areas. Other potential reasons which we discuss include the management of dams, particularly if preference is given to hydropower generation during lean seasonal flows, or more generally if water storage is inadequate. We also find that having access to vast groundwater reserves dampens the negative effects of dry shocks on cropland productivity. Differentiating between uses and sources can, therefore, provide key insights into the margins along which irrigation can buffer productivity from rainfall variability.