We show that the collapsar model of gamma-ray bursts results in a series of successive shocks and rarefaction waves propagating in the "cork" of stellar material being pushed ahead of the jet, as it emerges from the massive stellar progenitor. Our results are derived from analytical calculations assuming a hot, ultrarelativistic one-dimensional flow with an initial Lorentz factor Gamma(j)similar to100. The shocks result in a series of characteristic, increasingly shorter and harder thermal X-ray pulses, as well as a nonthermal gamma-ray pulse, which precede the usual nonthermal MeV gamma-rays. We consider jets escaping from both compact (CO or He dwarf) and blue supergiant stellar progenitors. The period, fluence, and hardness of the pulses serves as a diagnostic for the size and density of the outer envelope of the progenitor star.