Jenkins Job DSL

Jenkins job DSL is a plugin that allows us to define jobs in programmatic form with minimal effort.
DSL stands for Domain Specific Language.
You can describe your jobs in Jenkins using a Groovy Based Language.
Groovy-- It’s similar to java but simpler because it’s much more dynamic. It’'s Scripting Language.
- Jenkins job DSL plugin was designed to make it easier to manage jobs.
- If you don’t have a lot of jobs, using the UI is the easiest way.
- When the number of jobs grows, maintaining becomes difficult and a lot of work.
2. Jenkins job DSL plugin solve this problem and you get a lot of extra benefits.
Jenkins job DSL plugin example with npm install ( to install dependecies of Node.js project)
This is groovy syntax,
job('DSL example') { scm {
git('https://github.com/NilukaSripalim/ui-scenario-test.git') { node ->
// is hudson.plugins.git.GitSCM
node / gitConfigName('Niluka Sriplai')
node / gitConfigEmail('niluka@wso2.com')
}
}triggers {
scm('H/5 * * * *')
}
wrappers {
nodejs('nodejs') // this is the name of the NodeJS installation in // Manage Jenkins -> Configure Tools -> NodeJS Installations -> Name }
steps {
shell("npm install")
}
}
- The above example is going to create one job.


- scm-software configuration management
- In scm we have defined git repository, that should be the git repository which we are going to use in job
3, 4. Configure Git username, Configure Git email, this is for configuring git client in Jenkins
If you wouldn’t set these 2 parameters there should be a failure.
Jenkins will clone the repository, and we can run the commands which are mentioned in the git project, this repository will contain the index.js and package.json
Then how many times you need to build it,
triggers {
scm('H/5 * * * *')
}
That we can define in triggers, e.g. all the scm every 5 min
For wrappers, here we say that we are going to use node.js
wrappers {
nodejs('nodejs')// this is the name of the NodeJS installation in // Manage Jenkins -> Configure Tools -> NodeJS Installations -> Name }
If you wouldn’t find this wrapper you can't use command node or npm
So once we clone the GitHub project what are we going to do,
steps {
shell("npm install")
}
Here we define in steps, that we have shell step, need to do npm install command
npm install is done, download all the dependencies and make sure our project is ready to run.
👍 😄