In this work, we constrain the spectral index $n_t$ of the primordial gravitational wave power spectrum in a universe with sterile neutrinos by using the Planck temperature data, the WMAP 9-year polarization data, the baryon acoustic oscillation data, and the BICEP2 data. We call this model the $\Lambda$CDM+$r$+$\nu_s$+$n_t$ model. The additional massive sterile neutrino species can significantly relieve the tension between the Planck and BICEP2 data, and thus can reduce the possible effects of this tension on the fit results of $n_t$. To constrain the parameters of sterile neutrino, we also utilize the Hubble constant direct measurement data, the Planck Sunyaev-Zeldovich cluster counts data, the Planck CMB lensing data, and the cosmic shear data. We find that due to the fact that the BICEP2 data are most sensitive to the multipole $\ell\sim150$ corresponding to $k\sim0.01$ Mpc$^{-1}$, there exists a strong anticorrelation between $n_t$ and $r_{0.002}$ in the BICEP2 data, and this further results in a strongly blue-tilt spectrum. However, a slightly red-tilt tensor power spectrum is also allowed by the BICEP2 data in the region with larger value of $r_{0.002}$. By using the full data sets, we obtain $m_{\nu,{\rm{sterile}}}^{\rm{eff}}=0.48^{+0.11}_{-0.13}$ eV, $N_{\rm{eff}}=3.73^{+0.34}_{-0.37}$, and $n_t=0.96^{+0.48}_{-0.63}$ for the $\Lambda$CDM+$r$+$\nu_s$+$n_t$ model.