Jenkins — How Can We Get Started Jobs in Jenkins (Part 3)
By: Kasun Dissanayake
Tags: Jenkins, Jenkins Pipeline, Jenkins Job Builder

In the previous article, we learned how to create Users + Manage + Assign Roles in Jenkins. In this article, I will be highlighting how can we create some basic JOBS in Jenkins. Furthermore, these are the points which I am going to explain.

How to create a basic Job in Jenkins.

Basic Job Configurations.

How to run the Job remotely.

How to chain Job Execution

How to create a basic Job in Jenkins?

First of all click on New Item on the Jenkins Dashboard. Then Give a name to your project. Then you can select a Freestyle or Multi-configuration project. For this tutorial please go with the Freestyle project. Then click on the Okay button.

As soon as you complete these simple steps you will be taken to the configuration window. Here you can provide different details about Jobs. There are 5 sections available. General, Source Code Management, Build Triggers, Build, and Post-build Actions.

General Section

Here you can provide a quick description of your project or Job. You can preview it also. You can also use HTML tags inside the description.

Source Code Management Section

So here in case you want to take the build from any source code system like Git, Bitbucket, or any other source code management portals. We need to add plugins to those source code repositories. But in the coming tutorials, we will see how exactly we can get our build and trigger our Job from a source code management system.

Build Triggers Section

Here you can trigger builds remotely (e.g., from scripts), We can build after other projects are built and we can build periodically or poll SCM.

Poll SCM means that we have a Sourcecode management system and incase we have configured any SCM like get repository. As soon as a build takes place in that repository our job should get executed. We will discuss this later and now we will discuss what is build periodically means.

Build Periodically means that we can define an expression and based on that expression our job will be executed at some particular interval. If you want more information on that just click on the help icon on the right side corner. Then it will show you exactly what all the parameters. Just tick the Build periodically option and see.

So you have to give your syntax in this format.

MINUTE HOUR DOM MONTH DOW

Here you can assign a fixed periodic interval for your jobs using expressions.

Example :

Here it says that

Would last have run at Saturday, July 11, 2020 9:06:19 AM IST; would next run at Saturday, July 11, 2020 9:06:19 AM IST.

So here last run and the next run is at exactly the same time which means we are making to run our Jenkins to run in every minute.

If you just want another time interval use this.

# every fifteen minutes (perhaps at :07, :22, :37, :52)

H/15 * * * *

# every ten minutes in the first half of every hour (three times, perhaps at :04, :14, :24)

H(0-29)/10 * * * *

# once every two hours at 45 minutes past the hour starting at 9:45 AM and finishing at 3:45 PM every weekday.

45 9-16/2 * * 1-5

# once in every two hours slot between 9 AM and 5 PM every weekday (perhaps at 10:38 AM, 12:38 PM, 2:38 PM, 4:38 PM)

H H(9-16)/2 * * 1-5

# once a day on the 1st and 15th of every month except December

H H 1,15 1-11 *

Build Section

Here you can add any build step. If you are using windows then you can give some commands like dir or date or anything. If you are a Mac user you can give any bash command. Just select option form dropdown.

Post-build Actions Section

This is very important because after you build your project you will need to do something like,

You want to build another project after this project builds completed.

You want to send out some reports or notifications.

You want to trigger some acceptance tests or performance tests.

How to build a Job in Jenkins and get the Details of a Job?

Go to the Dashboard and you can see all the projects that you have already created.

I will explain the Dashboard projects table,

Status of the last build(1st Column) —You can see the status of the last build that you have already done. Red color for Build failed, Blue color for Build Success, and the Grey color for Build is not done yet.

Weather report(2nd Column) — This shows the aggregated status of recent builds. Based on the last 5 runs this 2nd column icon gets changed. Sunny icon for no recent builds failed (Success 100%). Cloudy sun icon for 1 out of the last 5 builds failed(Success 75%). Rainy Cloudy icon for 3 out of the last 5builds failed(Success 40%). Rainy Thunder icon for 4 out of the last 4 builds failed(Success 20%).

Last Success (4th Column)— Details about the last successful build and the build number and how much time it took to execute.

Last Failure (6th Column)— Details about the last unsuccessful build and the build number and how much time it took to execute.

Last Duration (7th Column)— What was the duration of your last build.

How to get the execution details of the Project?

Here just click on the project name and then you can see all the history of last builds on the left side of the Project Dashboard.

Build History

How to trigger a Job Remotely?

We discussed how to build a Job using the Jenkins Dashboard but now let’s discuss how to execute a Job from a remote place. Go to the project which you have already created and go to the Configure section. And open up the Build Triggers section. Now I am going to trigger build remotely(Just put a tick on the Trigger builds remotely option). As soon as you click it Jenkins gives you a URL.

Just copy it and paste it in your browser.

JENKINS_URL/job/TestProject1/build?token=TOKEN_NAME

My JENKINS_URL is http://localhost:8080/ and you can provide a token here. It is a kind of password. I have added 1234 as my Authentication token.

Now just click Apply and Save.

Now you can just go to any other system or any other browser and you can give your IP address instead of localhost and you can execute this command from any other machine as well. Then you can connect to this Jenkins machine.

Before going to this URL: Look at the TestProjct1, Last Success Build time and build Number.

After going to this URL: Now you can see that Build number 2 has already been successfully executed 6.7 seconds ago.

So we triggered this build from outside. We did not trigger it within Jenkins but from outside. So this is ho trigger your Jobs from outside, you just need a simple URL only.

How to chain Job executions?

First of all, you need a couple of projects in Jenkins. I have created 3 projects called TestProject1, TestProject2, and TestProject3.

We are going to do an execution chain here.

Go to Project 2 which is TestProject2 and go to Configure-> Build Triggers section. Then select Build after other projects are built. So the trigger for this particular project will come to another project. As soon as that project gets completed this project will get built.

Now here you can add multiple project names as your wish. You can just select Trigger only if the build is stable, Trigger even if the build is unstable and Trigger even if the build fails options too.

Here I am selecting Trigger only if the build is a stable option. It says that build the TestProject2 only if the build is stable for the TestProject1 project.

After that go to the Post-Build section. and select Build another project option. This is a post-build action that says after this particular project is built I want to build another project which is TestProject3. You can give multiple projects here and select the stable build options as previously I have explained.

Click Apply and Save.

Now Let’s execute the first project and see the chain is actually working or not. As soon as out TestProject1 is completed TestProject2 should get executed. As soon as our TestProject2 is get executed TestProject3 should get executed. This is how we chained these 3 projects.

Before Execution:

After Execution:

Here you can see the chain of the TestProjects execution. So this is all about Jobs in Jenkins. In the next tutorial, we will go very deeply and we will see how exactly we make different configurations and how we take out code from the repository and how can we trigger it.

Thank You!