  The goal of this work is to investigate Jupiter's growth focusing on the
amount of heavy elements accreted by the planet, and its comparison with recent
structure models. Our model assumes an initial core growth dominated by pebble
accretion, and a second growth phase that is characterized by a moderate
accretion of both planetesimals and gas. The third phase is dominated by
runaway gas accretion during which the planet becomes detached from the disk.
The second and third phases are computed in detail, considering two different
prescriptions for the planetesimal accretion and fits from hydrodynamical
studies to compute the gas accretion in the detached phase. In order for
Jupiter to consist of $\sim$20-40 $M_{\oplus}$ of heavy elements as suggested
by structure models, we find that Jupiter's formation location is preferably at
an orbital distance of $1\lesssim a \lesssim 10$ au once the accretion of
planetesimals dominates. We find that Jupiter could accrete between $\sim$1 and
$\sim$15 $M_{\oplus}$ of heavy elements during runaway gas accretion, depending
on the assumed initial surface density of planetesimals and the prescription
used to estimate the heavy-element accretion during the final stage of the
planetary formation. This would yield an envelope metallicity of $\sim$0.5 to
$\sim$3 times solar. By computing the solid accretion during the detached
phase, we infer a planetary mass-metallicity ($M_P$-$M_Z$) relation of $M_Z
\sim M_P^{2/5}$ when a gap in the planetesimal disk is created, and of $M_Z
\sim M_P^{1/6}$ without a planetesimal gap. Our hybrid pebble-planetesimal
model can account for Jupiter's bulk and atmospheric enrichment. The high bulk
metallicity inferred for many giant exoplanets is difficult to explain from
standard formation models. This might suggest a migration history for such
highly enriched giant exoplanets and/or giant impacts after the disk's
dispersal.
