1

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

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
raddirad
  • 331
  • 1
  • 8
  • 17

1 Answers1

2

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

Amityo
  • 5,635
  • 4
  • 22
  • 29