Reputation: 331
I have a large amount of pipeline script. The second half of them usually consists of the same code The redundand code looks a bit like this
stage 'Windows 7'
sh 'foo'
sh 'bar'
Stage 'Windows 8.1'
sh 'foo'
sh 'somethingelse'
I would like to export this code fragment into a file and then reuse it when I need it. What can I do to achieve this? Where Do I have to store the script to make it accessible?
Cheers
Upvotes: 1
Views: 1035
Reputation: 6321
Use Pipeline Shared Groovy Library plugin.
Create a new repository, put your groovy code under (root)/var/your_code.groovy
Load the libraries with @Library
or tick Manage Jenkins -> Configure System -> Global Pipeline Libraries -> Load Implicitly to always have the groovy code loaded
Upvotes: 2