General Questions - Jenkins DSL

Jenkins setup:
Jenkins 2.319.2 core

Hi Jenkins Expert,

I’m using the Jenkins Job DSL plugin and the jenkins declarative pipeline syntax for creating Jenkin jobs with multiple build stages. Issues I have:

  1. No quick/good way to test the DSL other than commit and push the code to trigger a job generation and then run the job. Is there a quicker way to do this?

  2. No good documentation on the data types and APIs. E.g. for the build step How do I know the return type of the build call? And what is data is available on the returned object?

  3. Is there a good way to check the underlying hudson.model related to the pipline syntax? It would be very helpful to be able to know the underlying Java type so I can look up what data/method is available.

Thanks in advance for any help!

Hello @current817 and welcome to this community. :wave:

Jenkins Job DSL scripts can be tested locally using the Gradle build tool and the Jenkins Job DSL Gradle Example project. Or at least, it used to be possible, the project has not moved in 7 years, so I can’t guarantee it still works.

Here’s a basic outline of the steps:

  • Clone the Jenkins Job DSL Gradle Example project from GitHub: git clone
  • Write your Job DSL scripts in the jobs directory of the cloned project.
  • Run the gradle test command to execute the tests.
  • Run the gradle runDsl command to create an XML output of the jobs.

This should allow you to test your Job DSL scripts without having to commit and push the code to Jenkins… at least, if the project still works.