Context : The fraction of galaxies bound in groups in the nearby Universe is high ( 50 % at z \sim 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 \leq 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 \leq 0.6 , with a wide range of virial masses ( 1.24 \times 10 ^ { 13 } \leq M _ { 500 } ( M _ { \sun } ) \leq 6.63 \times 10 ^ { 14 } ) and X-ray luminosities ( 2.27 \times 10 ^ { 41 } \leq L ^ { XXL } _ { 500 } ( erg s ^ { -1 } ) \leq 2.15 \times 10 ^ { 44 } ) . 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 , 22111 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 L ^ { XXL } _ { 500 } .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 .