We investigate the statistics of work performed on a noninteracting electron gas confined in a ring as a threaded magnetic field is turned on. For an electron gas initially prepared in a grand canonical state it is demonstrated that the Jarzynski equality continues to hold in this case, with the free energy replaced by the grand potential. The work distribution displays a marked dependence on the temperature. While in the classical (high-temperature) regime, the work probability density function follows a Gaussian distribution and the free energy difference entering the Jarzynski equality is null, the free energy difference is finite in the quantum regime, and the work probability distribution function becomes multimodal. We point out the dependence of the work statistics on the number of electrons composing the system.