3

Is it possible to create a pipeline inside a groovy script via a function call?

If I have a script such as:

def call() { pipeline { agent any stages { ... } } } 

then I can call this script in Jenkins with:

@Library('foo') _ foo() 

And I see the pipeline running with all of its stages.

But if I change the script so that the pipeline step is outside of the call() method and in its own method:

def build() { pipeline { agent any stages { ... } } } 

And call it via Jenkins:

@Library('foo') _ foo.build() 

then I get the following error:

java.lang.NoSuchMethodError: No such DSL method 'agent' found among steps [...] 

I'd really like to have the one script with build(), deploy(), release(), etc methods, each defining their own pipeline, but it seems that a pipeline can only be created via the call() method, and I'll need to have separate scripts for each pipeline (build.groovy, deploy.groovy, etc).

1
  • You could build a job from a running job, look at this. Commented Nov 19, 2019 at 23:54

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.