Having fun with the Jenkins DSL


Jenkins it's a outstanding deployment tool. I love Jenkins, i use for a very long time.  I remember when was called Hudson.  There are several things that made Jenkins one for the most used solutions for deploys. Jenkins has a awesome community with more than 1k plugins.

For this post i will cover a specific plugin called Jenkins Job DSL. This plugin gives you a Groovy DSL to code your Jobs, yes Code not XML. :-) This is good for lots of reasons. First of All in a DevOps context this allow you to automate the job creation which is tedious and manual. Moreover the DSL is great because it allow you to create a massive number of job, so in a microservices context lets say you have 50 microservices and all run in they own jetty and they code is on GitHub and build is done using maven. You can automate all that and create a JOB using the DSL this job will create the other jobs. Even if you have one job only for me it makes sense because you have it automated.

We will create a simple DSL and will invoke a bash script with download an builds Apache web server. The server version will be a build parameter so the user will pass this on the job when the build happens.

Groovy Job DSL for Jenkins

Bash Script to Build and Install Apache

Then you just need create a freestyle job and configure your favorite SCM provider. If you want just commit this 2 files into a GitHub account then point Jenkins there. And configure a DSL-JOB Step pointing to the groovy class:  ReleaseApache.groovy and that's it. When you run this job, Jenkins will generate another job for you. :-)

Cheers,
Diego Pacheco

Popular posts from this blog

C Unit Testing with Check

Having fun with Zig Language

HMAC in Java