Context. The fraction of galaxies bound in groups in the nearby Universe is high (50% at z ∼ 0). Systematic studies of galaxy properties in groups are important in order to improve our understanding of the evolution of galaxies and of the physical phenomena occurring within this environment. Aims. We have built a complete spectrophotometric sample of galaxies within X-ray detected, optically spectroscopically confirmed groups and clusters (G&C), covering a wide range of halo masses at z ≤ 0.6. Methods. In the context of the XXL survey, we analyse a sample of 164 G&C in the XXL-North region (XXL-N), at z ≤ 0.6, with a wide range of virial masses (1.24 × 1013 ≤ M500,scal(Mo) ≤ 6.63 × 1014) and X-ray luminosities ((2.27 × 1041 ≤ L500,scal XXL(erg-s-1) ≤ 2.15 × 1044)). The G&C are X-ray selected and spectroscopically confirmed. We describe the membership assignment and the spectroscopic completeness analysis, and compute stellar masses. As a first scientific exploitation of the sample, we study the dependence of the galaxy stellar mass function (GSMF) on global environment. Results. We present a spectrophotometric characterisation of the G&C and their galaxies. The final sample contains 132 G&C, 22 111 field galaxies and 2225 G&C galaxies with r-band magnitude <20. Of the G&C, 95% have at least three spectroscopic members, and 70% at least ten. The shape of the GSMF seems not to depend on environment (field versus G&C) or X-ray luminosity (used as a proxy for the virial mass of the system). These results are confirmed by the study of the correlation between mean stellar mass of G&C members and L500,scal XXL. We release the spectrophotometric catalogue of galaxies with all the quantities computed in this work. Conclusions. As a first homogeneous census of galaxies within X-ray spectroscopically confirmed G&C at these redshifts, this sample will allow environmental studies of the evolution of galaxy properties.