Many Minds
Published in

Many Minds

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.

  1. 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.
  1. scm-software configuration management
  2. 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.

👍 😄

--

--

--

The idea is to learn something for myself and share what I have learned.

Recommended from Medium

Getting On Board with Let, Const, & Arrow Functions

7 Best React development tools to try in 2022

react tools

JavaScript JSX, Element, Component, Virtual DOM

Nested BackboneJS Models

Tutorial: Build an Interactive Virtual Globe with Three.js

Getting, Posting, and Storing Data with ExpressJS and MongoDB

How to Build a Restaurant Menu App in Nuxt & Vuex using Cosmic JS

Imposter Syndrome

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Niluka Sripali Monnankulama

Niluka Sripali Monnankulama

An IT professional with over 3 years of experience. Member of the WSO2 Identity & Access Management Team.

More from Medium

Writing Pure Apex Unit Testing

Q&A: Models of IT products development — what is the difference

Agile Development in Software Engineering

Being a 10x Software Engineer — Short summery of Michael Lin’s Medium article