I’m trying to figure out something about declarative pipelines. I know that shared libraries can have entire pipelines as a last statement in call function; however, the pipeline would still have a predefined structure. What I’m wondering is whether it’s possible to compose and return a declarative pipeline from shared library. Eventually I’d like to achieve this:
library 'shared'
myPipeline {
stages {
...
}
}
myPipeline would then augment the stages block passed to it with other stages and properties, and return a pipeline. Just having scripted statements in stages doesn’t work obviously, I also tried to return parsed AST from shared library but that also doesn’t work. Maybe it can be accomplished by writing a plugin? Ideally this plugin would be just some glue code so that the logic can still be implemented in the shared library.
You might want to look into the idea of having jenkinsfile being generated by an external templating like script that updates your SCM, so by the time jenkins sees it, the Jenkinsfile is deterministic, plus it would be in CI if you ever needed to go back to a previous build.
Yeah you’re right – I meant it’s a script block within a declarative pipeline.
Yeah I saw that implemented once actually – with a microservice that would render Jenkinsfiles from templates stored in git.
I was just hoping there’s a way to achieve this by leveraging existing APIs and maybe writing some glue code plugin.
Anyway thanks for your answers again, I will probably stick with my example posted above. If you have any suggestions on the general direction to look at (like what code or plugins I could read), would appreciate if you let me know