Jenkins Jobs

Topics Covered

Overview

Suppose you are the CTO of a company and 20 developers are working with you on a single product. All the developers after implementing the assigned features push their changes to source code which is stored at version control say GitHub.

As CTO, your tasks mainly involve reviewing all the pushed changes by other developers implemented correctly or not, then merging these changes, then you will check for build status, in case of failure you have to identify the bug(s) and fix them. Then finally you will deploy these changes to the production environment.

What if you have to perform the same set of above steps repeatedly whenever there is any change in the source code repository?

Isn't it a long time-taking and non-efficient process?

Yes! It is.

So, Jenkins provides us with all of these functionalities within Jenkins Job. In this article, we will start with Jenkins's Job what it is, its types, and how to create one to give a hands-on experience in this article. So, let's start!

What are Jenkins Jobs?

Any kind of automation we do in Jenkins is nothing but called a Jenkins job. These automated process is not limited to below list but can include :

  1. Cloning the source code from where it is stored. (For example version control like Git etc. )
  2. Compiling the code.
  3. Based on the requirements, we can run unit tests as well.

An example of a set of tasks in Jenkins Job is shown below in diagram :

example

Note :

  • We define some set of tasks in Jenkins to perform, these tasks are nothing but a Jenkins job that runs sequentially.
  • The Jenkins jobs are the most important part of Jenkins's build process.
  • Jenkins job also allows us to merge the code using management tools like Superversion, CVS, CVN, perforce, etc.

Now before going in-depth learn about the various types of Jenkins Jobs available.

Let's look where you create one of them :

  1. Run your Jenkins (localhost) as a standalone application.
  2. Login into it.
  3. In the left column, click on the New Item.
  4. A list of different Jenkins jobs available will appear as shown below :

Let's discuss each of them in detail below!

Types Of Jenkins Jobs

Following are the various types of jenkins job available with different use cases as shown in the diagram also :

types of jenkins jobs

Freestyle Project

This is the most frequently used and popular Jenkins job or feature in Jenkins. It offers us to perform many operations. Using this feature, we can build the pipelines/scripts in Jenkins and can run them seamlessly.

Maven Project

It's useful when your application has POM files available, then you can build jobs in Jenkins using the Maven project. Jenkins by default after choosing this option, picks all the POM files, creates the configurations, and runs the builds.

Pipeline

It's useful to create a pipeline especially when you are dealing with long-running activities. Creating Jenkins jobs using the Freestyle project is not a good option and therefore, choosing the pipeline is the best option. In addition, to create pipelines in multiple branches, we can choose the multibranch Pipeline.

Multi-configuration Project

While testing we sometimes require to test the application in multiple configurations and in multiple environments, choosing this multi-configuration option allows us to do this.

Also, if you are working on an application that needs different configurations, this option will be the best to use.

Organization Folder

When you choose this option, Jenkins searches your Github user account among all Github user accounts to find that exact match of a repository. And then, it matches markers as defined.

Setup Build Jobs

Following are the steps to run your Jenkins Job :

Step 1:

Among all the jobs listed on the Jenkins dashboard, click on the job you want to perform. Then click on the Build Now option in the left column.

jenkins job build

Step 2: As soon as you click on the build now option, the build will get initialized. If you want to check the Build History, you refer to the Build History option in the left column.

jenkins job build history

Step 3: After the build has been completed, you can view the result of your build and can perform console output to verify the results.

jenkins job status verification and console output

The job Status can either be Success or Failure. In case of failure, find the error and make the corrections.

Congratulations! You have created your first Jenkins Jobs.

Conclusion

  • Any automation that we perform in Jenkins is a Jenkins job.
  • Using Jenkins Job, we can pull the source code from version control, create it build, run tests, verify the status of builds and deploy, etc.
  • Types of Jenkins Jobs are Freestyle Project, Maven Project, Pipeline, Multi-configuration Project, and GitHub Organization.
  • Running the Jenkins job manually requires only 3 steps. Choose a job, click on build Now, go to build history, view, and verify the build results.