jenkinsjenkins-job-dsl

How to know where a Jenkins job is created in groovy code


When a Jenkins JobDSL seed job finishes creating other jobs, it shows a list of generated jobs.
For example:

    GeneratedJob{name='my_example'}
    GeneratedJob{name='my_mvn-test'}

Is there a way to print out at which line and in which file a job is created?
For instance:

10: job ("${prefix}-${prodname}-${suffix}") {
11:     ...
...
20: }

Here line 10 is the location of job creation.
We have a big bunch of jobs generated in different dsl/groovy src files, and those jobs don't use fixed job names in the code, so it's hard to find where they are created without knowing the source code well.

Searched for things like Job DSL API hooks, but with no luck…


Solution

  • You can change your jobdsl code to print that information, you should be able to add println with custom messages anywhere in your code and log whatever is relevant to you.

    It requires changing your code but it's a one off cost and it's worth evaluating against your current maintenance cost.

    You can even add this information to the description of each job, so you don't depend on the seeder job logs.