DEV Community

TheBadCoder
TheBadCoder

Posted on

Jenkins: Create a simple build job

Jenkins job

The jenkins job is an individual task that could be useful for your CI CD pipeline. The job could download a code from git repository for you. It can also run some commands to say build the code that we downloaded, it can send the build report over email to the stake holders.

Note- I will be considering a java project for the the build job that we will be creating in this post.

Create Jenkins Job

Jenkins dashboard has an option to create a new job which is "New Item" and there are few things that we need to provide to the wizard.

  • Item name that is the Job name.
  • Type of the project, we will be selecting Freestyle project one for this one.
  • Click on the "OK" button. Create a job wizard

General Job Details

Add some description to the job that could be informative for the people working on the project.

  • Click on Advanced button
    Job Description and Advanced option for custom workspace configuration

  • Choose Use custom workspace option

  • For Directory, we will configure the local repository path of the code that we want to build using jenkins. example in my case C:\Users\myUser\Desktop\gitProjects\javaProjects\MyProject

  • Display name, this is self explanatory field I believe. say in my case I am going to use Project Ignite Local Build.
    Local workspace configuration

Source code management

As we are using local repository from our machine we will keep this option to auto selected None.
Git repository option will be explored in another post on jenkins.

Skip changing any of the things from Build Triggers and Build Environment we will be covering those things in later posts, right now we are focusing on simplest job that we can run.

Build

Here also jenkins provide many build options for different needs, what we are interested in is to do a simple build for our java code.

  • Click on "Add build step".
  • Select "Execute windows batch command" option.
  • Enter the command that you would run to create a build from your code if you were to do it manually. In my case I will be using "mvn package". Build step configuration

Again skip post build actions section as it is in the future scope of the series on jenkins.

Click on "Save" button to save the job.

Now we have our job ready to be executed, from Job Page you can click "Build now" button to run the job !!

Build history

We can see the job running with some #BuildNumber and if you wish to see the details of that particular job you can click on it.
You can see the changes in the build, also the console logs.
The build will be green if it was successful and red if it failed, while running stage the build will be shown in blue color.

The artifacts generated by the build can be found in the local repository where it usually gets generated when you execute the build manually so for my build I will find the generated jar in target folder.

Hope you like the post, if you feel there are any improvements needed for the post please do share.

Top comments (0)