Issue
We have our shared libraries on gitlab called mainlibrary
and it has a lot of groovy files.
Example in mainlibrary gitlab repo we have the following files.
startup_pipeline.groovy
cleanup_pipeline.groovy
In one of our Jenkins job we need to include multiple groovy files in the Jenkinsfile
. Is this possible?
This is how the Jenkinsfile
looks like:
@Library('mainlibrary')_
startup_pipeline(email:'[email protected]')
Can I include the second groovy function file into this Jenkinsfile
like this?
@Library('mainlibrary')_
startup_pipeline(email:'[email protected]'),
cleanup_pipeline(email:'[email protected]')
Solution
Considering the cleanup_pipeline.groovy
is located under the vars
folder and your code already has a complete declaration inside, your example may work, and the second file can be included. The only modification is the extra comma:
@Library('mainlibrary')_
startup_pipeline(email:'[email protected]')
cleanup_pipeline(email:'[email protected]')
Or can be under src
and imported, but I never used this approach.
Usually, I keep the main logic inside vars
, and other complex things go to src
.
Based on Jenkins documentation, see more in Directory structure and Defining custom steps.
Video step by step building a shared library, you can build and test something similar if you are not sure about the structure.
Answered By - sumitani
Answer Checked By - David Marino (JavaFixing Volunteer)