Jenkins Job DSL Playground – how it works

Working with Jenkins Job DSL code sometimes is a pain in the neck. Especially if you have very big and complex scripts. You can make a mistake very quickly, so it would be great if there could be a way to test your code before the seed deployment. Of course, you can test your DSL scripts outside of Jenkins, but sometimes you don’t need to run the whole bunch of tests, right? You just want to check only the small part of your code… What if I tell you that you can do that? Ladies and gentleman, let me introduce you to Jenkins Job DSL Playground!

What is the Jenkins Job DSL Playground?

In short, Jenkins Job DSL Playground is a web application allows you to “transform” your DSL code into the Jenkins XML config. It should be known by every Jenkins Administrator using DSL, it goes without saying! There are several ways of using this application:

Regardless of which way you will use, the final effect will be the same. You will have access to the simple UI split into the two parts: a place where you can add your code and second column with the execution result. The right column is the place with an XML code – exactly the same as Jenkins XML configuration files. Actually, it’s the only one, certain method to check whether your DSL code does exactly what you want.

Job DSL Playground empty fields

How to use Jenkins Job DSL Playground

Everything you find below is based on the official application, available at http://job-dsl.herokuapp.com. But don’t worry – there are no differences between that web app and docker image or the app built from the source code. If you want to use a docker, you can read more about how to build and run the image in my post: Jenkins Job DSL Playground Docker image. But if you would prefer a classic way, just visit the project repository on GitHub and follow the instruction in README file.

TL;DR version
  1. Go to the application in your web browser
  2. Type or paste your DSL code into the left column
  3. Check if there are no errors during the XML generation.
  4. Check if generated XML in the right column matches your expectations.
Longer version

First, you need to open the application in your web browser. You can do that by typing http://job-dsl.herokuapp.com (or http://localhost:5050 or similar if you use your own app). After that you will see the following UI:

Job DSL Playground empty fields

Now, paste or type your DSL code to the left column of Jenkins Job DSL Playground. Let me show you an example:

As the result, you should see the following XML:

And as the image:

Jenkins Job DSL Playground result

As you can see, it’s exactly the same code, as when we create a similar job, but via Jenkins GUI. Thanks to that, we can easily check whether our code matches our expectations.

Jobs troubleshooting with Jenkins Job DSL Playground

But that’s not all! Let’s try to put the following code to our Jenkins Job DSL Playground:

Do you see what is wrong with that code? No? So please check the output from the right column. In that case, we don’t receive an XML, but an error with the full stacktrace. There you have the most important part:

Don’t you see still what is the problem? We’ve tried to pass the following types of parameters:

(java.lang.String, java.lang.String, java.lang.String)

but we should use: (java.lang.String, boolean, java.lang.String)

We used String instead of Boolean. Yes, Jenkins Job DSL Playground helps us also with such mistakes. Also if we forget to close the brackets, output in the right column will say us about that. Something like this:

will alert us, that we’ve missed the bracket:

Easy, right? Easy and very helpful. Just try it on your own and if you have any question, I will try to answer on all of them.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.