How to load another groovy script in the same Jenkins node? How to load another groovy script in the same Jenkins node? jenkins jenkins

How to load another groovy script in the same Jenkins node?


How about stashing the workspace after the checkout and before the script load?:

e.g.

stash includes: '**', name: "source"

and then unstash it in another node(){} section:

e.g. unstash "source"

That way it will be available in the other node

Don't forget to clean up the workspace though

Or how about creating a common function that contains the logic for the checkout too (maybe passing in branches as a param). Then you can discard the node(){} in the Jenkins file and just use node(){} entries in your shared groovy script?

e.g. Jenkinsfile

load 'common-pipeline.groovy'createWorlflow("*/master")

common-pipeline.groovy:

def createWorkflow(branches){node() {        def functions = load 'common/functions.groovy'        functions.checkout(branches)        functions.build()        functions.release()        functions.deploy()    }}


You can make a parameterized job for the second pipeline and use the parameter to control the node when triggering the second job.

The second pipeline would look like this:

node(runhereParam) {}