The behaviour of a dislocation pileup with a finite-strength source is investigated in the presence of various stress gradients within a continuum model where a free-dislocation region exists around the source. Expressions for dislocation density and stress field within the pileup are derived for the situation where there are first and second spatial gradients in applied stress. For a pileup configuration under an applied stress, yielding occurs when the force acting on the leading dislocations at the pileup tips reaches the obstacle strength, and at the same time, it is required that the source be at the threshold stress for dislocation production. A numerical methodology is presented to solve the underlying equations that represent the yielding conditions. The yield stress calculated for a pileup configuration is found to depend on stress gradients, obstacle spacing and source/obstacle strengths. It increases with increasing the first stress gradient, yet dependent on the second stress gradient. Furthermore, while the dependency of yield stress on the obstacle spacing intensifies with increasing the first stress gradient, it diminishes with an increase of second stress gradient. Therefore, the second stress gradient, as a newly introduced parameter, can provide a new physical insight into the size-dependent plasticity phenomena at small length scales.