Measurements of the associated production of vector bosons, W or Z (decaying to one or two leptons), and jets originating from heavy-flavour quarks are reported using data corresponding to integrated luminosities of 19.7 (35.7) ${\rm fb}^{-1}$, at centre-of-mass energies of 8 (13) TeV collected by the CMS detector at the CERN LHC. Total and differential cross sections as a function of several kinematic observables are measured and compared with several theoretical predictions.The production of a Z boson associated with a c-quark allows probing and constraining the charm quark content of the proton and may give insight into the existence of an intrinsic charm quark component inside the proton. The production of a W boson associated with a c-quark allows probing and constraining the strange quark content of the proton.