Can you re-use code for a number of different jobs in Jenkins casc?

64 Views Asked by At

I have a number of pipelinejobs in Jenkins casc with the following directory structure:

jobs/
  - Lab1_Job1.groovy
  - Lab1_Job2.groovy
  ...
  - Lab1_Job10.groovy
  - Lab2_Job1.groovy
  - Lab2_Job2.groovy
  ...
  - Lab2_Job10.groovy
  - Lab3_Job1.groovy
  - Lab3_Job2.groovy
  ...
  - Lab3_Job10.groovy

Due to the nature of our tests, we need to know the results of jobs specific to the hardware in a given lab. Therefore, we have a different file for each job (1-10) for each server (1-3). The code for each job is relatively similar other than a few environment variables.

Is there a more efficient way to do this? The issue is this has become hard to maintain, since a change in one file requires a change in atleast 2 other places. It would be great if all the jobs could pull code from a central template, but we also need them to be distinct separate jobs. Does such a method exist in Jenkins dsl/casc?

0

There are 0 best solutions below