The most flexible solution is a Pattern Brush. This is what joojaa meant with "the gradient does not need to be that path" - the gradient is simply a pattern applied to the path.
- because Illustrator doesn't accept gradients in brushes, you need to create a blend object. Draw 3 rectangles and fill them with the colors of your pipe + shadow profile.
- Blend Tool (W) and click on each rectangle in sequence, like this:
- Drag the blend object to the Brushes panel (F5 if it's not open) and select Pattern Brush
- Adjust the settings for the corners
- draw a "spine" for your pipe - a single open path with no fill
- Select the brush on the Brushes panel to apply to your pipe:
- you can easily change the colors of the gradient later
- you can easily change the shape of the pipe afterwards
- you can apply the same pattern to other objects