Magnetic flux ropes (MFRs) are believed to be one kind of fundamental structures in solar eruptions, of which the formation is being intensely studied. Here we report a rapid buildup process of an MFR during a confined X2.2 class flare that occurred on 2017 September 6 in NOAA AR 12673, three hours after which the MFR erupted as a major coronal mass ejection (CME) accompanied by an X9.3 class flare. For the X2.2 class flare, we do not find separation of the two flare ribbons and clear CME signature in the coronagraph images, suggesting it to be confined. For the X9.3 class flare, apparent separation of the two ribbons and a CME show it to be an eruptive one. We perform a time sequence of nonlinear force-free fields (NLFFFs) extrapolations covering the two flares and find that: although the flux-weighted mean twist number of the MFR was almost unchanged prior to the eruptive flare, the axial flux and magnetic helicity of the MFR were dramatically enhanced after the confined flare, as much as 86% for the former and 260% for the latter. The above three parameters were all significantly reduced after the eruptive flare. It clearly evidences the buildup and release of the MFR during the confined and eruptive flare, respectively. The buildup of the MFR may be achieved by reconnection during the confined flare. We also calculate the pre-flare distributions of the decay index above the main polarity inversion line (PIL) and do not find any significant difference. It indicates that the enhancement of the MFR flux may play a role in facilitating the subsequent successful eruption.