A class of complex Ginzburg-Landau (CGL) equations with variable coefficients is solved exactly by means of the Hirota bilinear method. Two novel features, elaborated in recent works on the bilinear method, are incorporated. One is a modified definition of the bilinear operator, which has been used to construct pulse, hole and front solutions for equations with constant coefficients. The other is the usage of time-or space-dependent wave numbers, which was employed to handle nonlinear Schrödinger (NLS) equations with variable coefficient. One-soliton solutions of the CGL equations with variable coefficients are obtained in an analytical form. A restriction imposed by the method is that the coefficient of the second-order dispersion must be real. However, nonlinear, loss (or gain) is permitted. A simple example of an exponentially modulated dispersion profile is worked out in detail to illustrate the principle. The competition between the linear gain and nonlinear loss, and vice versa, is investigated. The analytical solutions for solitary pulses are tested in direct simulations. The amplified pulses are very robust, provided that the linear gain is reasonably small. The results may be implemented in soliton fiber lasers.