added ability to share stage definition between pipelines.

moved stage initialization to pipeline function, the stage function
only generates a few spec and doesn't require any resource at all.