Split Pipeline script into multiple files -- run it without unnecessary nodes

5,517 views
Skip to first unread message

Christian Ditscher

unread,
Jun 15, 2016, 6:46:26 AM6/15/16
to Jenkins Users
Hello,

I use a seperate reopsitory for my pipeline script. Multiple Jenkins Jobs use this pipeline script to built different Projects. For better maintainability the pipeline itself consists of a main script and multiple other sript files in which I implemented the different stages.
The pipelines are started by the built in function of Jenkins to checkout a Pipelinescript from SCM. Here I have configured the main pipeline script to be run. This main script then uses "load" to start the different stages.

The thing that annoys me is that the "load" command needs to be contained inside a node {..} block.  This means I have to checkout the script files again on a node to "load" it. The scripts are already checked out on the master after "loading the script from SCM". I simply want to use the Flyweight executor to run the content of the stage script).  A bad solution would be to have the whole pipeline in one big script file. This would work but is really confusing.

Is there a way to tell the main script (which runs on the master) to "insert" another groovy file (already present on master)?

Any Ideas?

Thanks
Chris


Note:
In the Pipeline documentation I found the following but this still needs to checkout the scripts to a new node every time I want to load something.
node {
    git ''
    load 'pipeline.groovy'
}()

Ok, I could dedicate a single node like node('pipelineControl') so the scripts have to be be checked out only once but this solution still doesn't convince me.

Sverre Moe

unread,
Jun 15, 2016, 9:00:36 AM6/15/16
to Jenkins Users
Take a look at Pipeline Global Library https://github.com/jenkinsci/workflow-cps-global-lib-plugin
I started with the same problem as you now have and solved it by using global pipeline scripts.
These global script are stored in Jenkins git repository workflowLibs.git and can be accessed within all pipeline scripts.

Christian Ditscher

unread,
Jun 15, 2016, 9:46:59 AM6/15/16
to Jenkins Users
Hi, 

thanks .. this seems to look like this will solve my problem...
Will report back if it doesn't
Reply all
Reply to author
Forward
0 new messages