Context. We present time-resolved spectroscopy and photometry of HS 0218+3229, a new long-period cataclysmic variable discovered within the Hamburg Quasar Survey. It is one of the few systems that allow a dynamical measurement of the masses of the stellar components. Aims. We combine the analysis of time-resolved optical spectroscopy and R-band photometry with the aim of measuring the mass of the white dwarf and the donor star and the orbital inclination. Methods. Cross-correlation of the spectra with K-type dwarf templates is used to derive the radial velocity curve of the donor star. An optimal subtraction of the broadened templates is performed to measure the rotational broadening and constrain the spectral type of the donor. Finally, an ellipsoidal model is fitted to the R-band light curve to obtain constraints upon the orbital inclination of the binary system. Results. The orbital period of HS 0218+3229 is found to be 0.297229661 +- 0.000000001 d (7.13351186 +- 0.00000002 h), and the amplitude of the donors radial velocity curve is K2 = 162.4 +- 1.4 km/s. Modelling the ellipsoidal light curves gives an orbital inclination in the range i = 59 +- 3 deg. A rotational broadening between 82.4 +- 1.2 km/s and 89.4 +- 1.3 km/s is found when assuming zero and continuum limb darkening, respectively. The secondary star has most likely a spectral type K5 and contributes ~ 80-85% to the R-band light. Our analysis yields a mass ratio of 0.52 < q < 0.65, a white dwarf mass of 0.44 < M1(Msol) < 0.65, and a donor star mass of 0.23 < M2(Msol) < 0.44. Conclusions. We find that the donor star in HS 0218+3229 is significantly undermassive for its spectral type. It is therefore very likely that it has undergone nuclear evolution prior to the onset of mass transfer.