  We study how the proportion of star-forming galaxies evolves between z=0.8
and z=0 as a function of galaxy environment, using the [OII] line in emission
as a signature of ongoing star formation. Our high-z dataset comprises 16
clusters, 10 groups and another 250 galaxies in poorer groups and the field at
z=0.4-0.8 from the ESO Distant Cluster Survey, plus another 9 massive clusters
at similar redshifts. As a local comparison, we use samples of galaxy systems
selected from the Sloan Digital Sky Survey at 0.04< z < 0.08. At high-z most
systems follow a broad anticorrelation between the fraction of star-forming
galaxies and the system velocity dispersion. At face value, this suggests that
at z=0.4-0.8 the mass of the system largely determines the proportion of
galaxies with ongoing star formation. At these redshifts the strength of star
formation (as measured by the [OII] equivalent width) in star-forming galaxies
is also found to vary systematically with environment. Sloan clusters have much
lower fractions of star-forming galaxies than clusters at z=0.4-0.8 and, in
contrast with the distant clusters, show a plateau for velocity dispersions $
\ge 550 km s^-1$, where the fraction of galaxies with [OII] emission does not
vary systematically with velocity dispersion. We quantify the evolution of the
proportion of star-forming galaxies as a function of the system velocity
dispersion and find it is strongest in intermediate-mass systems (sigma ~
500-600 km s^-1 at z=0). To understand the origin of the observed trends, we
use the Press-Schechter formalism and the Millennium Simulation and show that
galaxy star formation histories may be closely related to the growth history of
clusters and groups. We propose a scheme that is able to account for the
observed relations between the star-forming fraction and \sigma [abridged].
