  We study gauge mediation in a wide class of O'Raifeartaigh type models where
supersymmetry breaking metastable vacuum is created by gravity and/or quantum
corrections. We examine their thermal evolution in the early universe and the
conditions under which the susy breaking vacuum can be selected. It is
demonstrated that thermalization typically makes the metastable supersymmetry
breaking cosmologically disfavoured but this is not always the case. Initial
conditions with the spurion displaced from the symmetric thermal minimum and a
small coupling to the messenger sector can result in the realization of the
susy breaking vacuum even if the reheating temperature is high. We show that
this can be achieved without jeopardizing the low energy phenomenology. In
addition, we have found that deforming the models by a supersymmetric mass term
for messengers in such a way that the susy breaking minimum and the susy
preserving minima are all far away from the origin does not change the
conclusions. The basic observations are expected to hold also in the case of
models with an anomalous U(1) group.
