Explore Courses
course iconScrum AllianceCertified ScrumMaster (CSM) Certification
  • 16 Hours
Best seller
course iconScrum AllianceCertified Scrum Product Owner (CSPO) Certification
  • 16 Hours
Best seller
course iconScaled AgileLeading SAFe 6.0 Certification
  • 16 Hours
Trending
course iconScrum.orgProfessional Scrum Master (PSM) Certification
  • 16 Hours
course iconScaled AgileSAFe 6.0 Scrum Master (SSM) Certification
  • 16 Hours
course iconScaled Agile, Inc.Implementing SAFe 6.0 (SPC) Certification
  • 32 Hours
Recommended
course iconScaled Agile, Inc.SAFe 6.0 Release Train Engineer (RTE) Certification
  • 24 Hours
course iconScaled Agile, Inc.SAFe® 6.0 Product Owner/Product Manager (POPM)
  • 16 Hours
Trending
course iconKanban UniversityKMP I: Kanban System Design Course
  • 16 Hours
course iconIC AgileICP Agile Certified Coaching (ICP-ACC)
  • 24 Hours
course iconScrum.orgProfessional Scrum Product Owner I (PSPO I) Training
  • 16 Hours
course iconAgile Management Master's Program
  • 32 Hours
Trending
course iconAgile Excellence Master's Program
  • 32 Hours
Agile and ScrumScrum MasterProduct OwnerSAFe AgilistAgile CoachFull Stack Developer BootcampData Science BootcampCloud Masters BootcampReactNode JsKubernetesCertified Ethical HackingAWS Solutions Artchitct AssociateAzure Data Engineercourse iconPMIProject Management Professional (PMP) Certification
  • 36 Hours
Best seller
course iconAxelosPRINCE2 Foundation & Practitioner Certificationn
  • 32 Hours
course iconAxelosPRINCE2 Foundation Certification
  • 16 Hours
course iconAxelosPRINCE2 Practitioner Certification
  • 16 Hours
Change ManagementProject Management TechniquesCertified Associate in Project Management (CAPM) CertificationOracle Primavera P6 CertificationMicrosoft Projectcourse iconJob OrientedProject Management Master's Program
  • 45 Hours
Trending
course iconProject Management Master's Program
  • 45 Hours
Trending
PRINCE2 Practitioner CoursePRINCE2 Foundation CoursePMP® Exam PrepProject ManagerProgram Management ProfessionalPortfolio Management Professionalcourse iconAWSAWS Certified Solutions Architect - Associate
  • 32 Hours
Best seller
course iconAWSAWS Cloud Practitioner Certification
  • 32 Hours
course iconAWSAWS DevOps Certification
  • 24 Hours
course iconMicrosoftAzure Fundamentals Certification
  • 16 Hours
course iconMicrosoftAzure Administrator Certification
  • 24 Hours
Best seller
course iconMicrosoftAzure Data Engineer Certification
  • 45 Hours
Recommended
course iconMicrosoftAzure Solution Architect Certification
  • 32 Hours
course iconMicrosoftAzure Devops Certification
  • 40 Hours
course iconAWSSystems Operations on AWS Certification Training
  • 24 Hours
course iconAWSArchitecting on AWS
  • 32 Hours
course iconAWSDeveloping on AWS
  • 24 Hours
course iconJob OrientedAWS Cloud Architect Masters Program
  • 48 Hours
New
course iconCareer KickstarterCloud Engineer Bootcamp
  • 100 Hours
Trending
Cloud EngineerCloud ArchitectAWS Certified Developer Associate - Complete GuideAWS Certified DevOps EngineerAWS Certified Solutions Architect AssociateMicrosoft Certified Azure Data Engineer AssociateMicrosoft Azure Administrator (AZ-104) CourseAWS Certified SysOps Administrator AssociateMicrosoft Certified Azure Developer AssociateAWS Certified Cloud Practitionercourse iconAxelosITIL 4 Foundation Certification
  • 16 Hours
Best seller
course iconAxelosITIL Practitioner Certification
  • 16 Hours
course iconPeopleCertISO 14001 Foundation Certification
  • 16 Hours
course iconPeopleCertISO 20000 Certification
  • 16 Hours
course iconPeopleCertISO 27000 Foundation Certification
  • 24 Hours
course iconAxelosITIL 4 Specialist: Create, Deliver and Support Training
  • 24 Hours
course iconAxelosITIL 4 Specialist: Drive Stakeholder Value Training
  • 24 Hours
course iconAxelosITIL 4 Strategist Direct, Plan and Improve Training
  • 16 Hours
ITIL 4 Specialist: Create, Deliver and Support ExamITIL 4 Specialist: Drive Stakeholder Value (DSV) CourseITIL 4 Strategist: Direct, Plan, and ImproveITIL 4 Foundationcourse iconJob OrientedData Science Bootcamp
  • 6 Months
Trending
course iconJob OrientedData Engineer Bootcamp
  • 289 Hours
course iconJob OrientedData Analyst Bootcamp
  • 6 Months
course iconJob OrientedAI Engineer Bootcamp
  • 288 Hours
New
Data Science with PythonMachine Learning with PythonData Science with RMachine Learning with RPython for Data ScienceDeep Learning Certification TrainingNatural Language Processing (NLP)TensorflowSQL For Data Analyticscourse iconIIIT BangaloreExecutive PG Program in Data Science from IIIT-Bangalore
  • 12 Months
course iconMaryland UniversityExecutive PG Program in DS & ML
  • 12 Months
course iconMaryland UniversityCertificate Program in DS and BA
  • 31 Weeks
course iconIIIT BangaloreAdvanced Certificate Program in Data Science
  • 8+ Months
course iconLiverpool John Moores UniversityMaster of Science in ML and AI
  • 750+ Hours
course iconIIIT BangaloreExecutive PGP in ML and AI
  • 600+ Hours
Data ScientistData AnalystData EngineerAI EngineerData Analysis Using ExcelDeep Learning with Keras and TensorFlowDeployment of Machine Learning ModelsFundamentals of Reinforcement LearningIntroduction to Cutting-Edge AI with TransformersMachine Learning with PythonMaster Python: Advance Data Analysis with PythonMaths and Stats FoundationNatural Language Processing (NLP) with PythonPython for Data ScienceSQL for Data Analytics CoursesAI Advanced: Computer Vision for AI ProfessionalsMaster Applied Machine LearningMaster Time Series Forecasting Using Pythoncourse iconDevOps InstituteDevOps Foundation Certification
  • 16 Hours
Best seller
course iconCNCFCertified Kubernetes Administrator
  • 32 Hours
New
course iconDevops InstituteDevops Leader
  • 16 Hours
KubernetesDocker with KubernetesDockerJenkinsOpenstackAnsibleChefPuppetDevOps EngineerDevOps ExpertCI/CD with Jenkins XDevOps Using JenkinsCI-CD and DevOpsDocker & KubernetesDevOps Fundamentals Crash CourseMicrosoft Certified DevOps Engineer ExperteAnsible for Beginners: The Complete Crash CourseContainer Orchestration Using KubernetesContainerization Using DockerMaster Infrastructure Provisioning with Terraformcourse iconTableau Certification
  • 24 Hours
Recommended
course iconData Visualisation with Tableau Certification
  • 24 Hours
course iconMicrosoftMicrosoft Power BI Certification
  • 24 Hours
Best seller
course iconTIBCO Spotfire Training
  • 36 Hours
course iconData Visualization with QlikView Certification
  • 30 Hours
course iconSisense BI Certification
  • 16 Hours
Data Visualization Using Tableau TrainingData Analysis Using Excelcourse iconEC-CouncilCertified Ethical Hacker (CEH v12) Certification
  • 40 Hours
course iconISACACertified Information Systems Auditor (CISA) Certification
  • 22 Hours
course iconISACACertified Information Security Manager (CISM) Certification
  • 40 Hours
course icon(ISC)²Certified Information Systems Security Professional (CISSP)
  • 40 Hours
course icon(ISC)²Certified Cloud Security Professional (CCSP) Certification
  • 40 Hours
course iconCertified Information Privacy Professional - Europe (CIPP-E) Certification
  • 16 Hours
course iconISACACOBIT5 Foundation
  • 16 Hours
course iconPayment Card Industry Security Standards (PCI-DSS) Certification
  • 16 Hours
course iconIntroduction to Forensic
  • 40 Hours
course iconPurdue UniversityCybersecurity Certificate Program
  • 8 Months
CISSPcourse iconCareer KickstarterFull-Stack Developer Bootcamp
  • 6 Months
Best seller
course iconJob OrientedUI/UX Design Bootcamp
  • 3 Months
Best seller
course iconEnterprise RecommendedJava Full Stack Developer Bootcamp
  • 6 Months
course iconCareer KickstarterFront-End Development Bootcamp
  • 490+ Hours
course iconCareer AcceleratorBackend Development Bootcamp (Node JS)
  • 4 Months
ReactNode JSAngularJavascriptPHP and MySQLcourse iconPurdue UniversityCloud Back-End Development Certificate Program
  • 8 Months
course iconPurdue UniversityFull Stack Development Certificate Program
  • 9 Months
course iconIIIT BangaloreExecutive Post Graduate Program in Software Development - Specialisation in FSD
  • 13 Months
Angular TrainingBasics of Spring Core and MVCFront-End Development BootcampReact JS TrainingSpring Boot and Spring CloudMongoDB Developer Coursecourse iconBlockchain Professional Certification
  • 40 Hours
course iconBlockchain Solutions Architect Certification
  • 32 Hours
course iconBlockchain Security Engineer Certification
  • 32 Hours
course iconBlockchain Quality Engineer Certification
  • 24 Hours
course iconBlockchain 101 Certification
  • 5+ Hours
NFT Essentials 101: A Beginner's GuideIntroduction to DeFiPython CertificationAdvanced Python CourseR Programming LanguageAdvanced R CourseJavaJava Deep DiveScalaAdvanced ScalaC# TrainingMicrosoft .Net Frameworkcourse iconSalary Hike GuaranteedSoftware Engineer Interview Prep
  • 3 Months
Data Structures and Algorithms with JavaScriptData Structures and Algorithms with Java: The Practical GuideLinux Essentials for Developers: The Complete MasterclassMaster Git and GitHubMaster Java Programming LanguageProgramming Essentials for BeginnersComplete Python Programming CourseSoftware Engineering Fundamentals and Lifecycle (SEFLC) CourseTest-Driven Development for Java ProgrammersTypeScript: Beginner to Advanced

Jenkins Jobs: Configuring SCM, Build Jobs & Polling SCM

By Mayank Modi

Updated on Oct 07, 2022 | 16 min read

Share:

Jenkins is one of DevOps's most widely adopted CI solutions. Jenkins CI is a continuous open-source integration and delivery server. The evolution of cloud computing and DevOps has increased its popularity and made it a popular choice among software developers and DevOps engineers. 

Jenkins CI allows developers to automate building, testing, and deploying code effortlessly. Also, it hones the capabilities to handle any build or continuous integration. Jenkins Jobs focuses on building and testing code continuously so that any changes made in the source code are easily integrated into the build. Best of all, Jenkins makes it easy to catch up on errors quickly, which is otherwise strenuous and time-consuming using manual processes.

In this Jenkins tutorial, we will see Jenkins in action. Starting with Jenkins Jobs and its types, our discussion will continue up to triggering builds and scheduling jobs in Jenkins. With the help of an example, we will show you how to create a Jenkins Job. Additionally, we will configure, trigger, and schedule the Jenkins job. Finally, triggering another job in Jenkins post-build will also be discussed at the end of this guide.  

Let's Start!

What are Jenkins Jobs?

Jenkins Jobs are a given set of tasks that runs sequentially as defined by the user. Any automation implemented in Jenkins is a Jenkins Job. These jobs are a significant part of Jenkins's build process. We can create and build Jenkins jobs to test our application or project. 

When working with Jenkins, the term “Jenkins Job” and “Jenkins Project” are synonymous. With a Jenkins Job, you can clone source code from version control like Git, compile the code, and run unit tests based on your requirements. Also, Jenkins allows you to merge code using other code management tools like Superversion, CVS, CVN, perforce, etc.  

Enroll in the Jenkins Certification Course from KnowledgeHut to kick-start your journey in Jenkins from scratch. We have industry-level experts to help you learn most effectively.

Types Of Jenkins Jobs

There are different Jenkins Job types available intended for different purposes. Based on the complexity and nature of your project, you can choose the one that best suits your needs. Let us look at the different types of jobs in Jenkins briefly:

Job Type Description
Freestyle Project This is the central and the most widely used feature in Jenkins. It is an available Jenkins build job offering multiple operations. Using this option, you can build and run pipelines or scripts seamlessly.
Maven Project If your work involves managing and building projects containing POM files, you prefer using Maven Project to build jobs in Jenkins. On choosing this option, Jenkins, by default, will pick the POM files, make configurations, and run builds.
Pipeline Freestyle Project is often not a good option to create Jenkins Jobs. Therefore, Pipeline is the best option. Use the option Pipeline for creating Jenkins Jobs, especially when working on long-running activities.
Multi-configuration Project If you are working on a project requiring multiple configurations, you prefer to use the Multi-configuration Project option. This option allows for making multiple configurations for testing in multiple environments.
GitHub Organization If you click on this option, it scans the User's GitHub account for all repositories. And then, it matches markers as defined.

Are you new to DevOps and looking to jump-start your career in this industry? Register for the most demanding DevOps Training and Certification from KnowledgeHut. We have openings for all from the beginner’s course to expert-level training. Enroll today! 

Setup Build Jobs

It is essential to create a Jenkins build job before we initiate the build. In this section, we will create our first Jenkins Job and complete the initial setup. 

1. Create a New Item 

Initially, we will create a Jenkin Job using the steps discussed below: 

  • Step 1: Go to the Jenkins Home Page and verify your credentials. 
  • Step 2: Sign in to your Jenkins account.
  • Step 3: In the Jenkins dashboard, click on New Item as shown:

Note: In our tutorial, we have created a New Item named Demo Jenkins Jobs using the Freestyle Project option for simplicity. Other options are available to choose the type of Jenkins Job type you prefer based on your project needs.  

Upon clicking the OK button, you will have your first Jenkins Job ready.

Similarly, we can create as many Jenkins Jobs per our requirements. The procedure for creating jobs remains the same. In the next section, we will configure our newly created Jenkins Job. 

Configuring Source Code Management

Once we have successfully created our Jenkins Job, the next task is configuring. In this section, we will configure the source code of our Jenkins Jobs using the FreeStyle Job in Jenkins. Follow the below steps to complete the necessary Jenkins configuration: 

1. Navigate to the Configure section as shown:

Clicking on the configure option will direct you to the Configuration page.

2. Fill in the “Description” section using the following steps: 

  • Step-1: Click on General. 
  • Step-2: Specify the Jenkins Jobs detail on the “Description” page: 
  • Step-3: Save the changes.

Besides Description, there are other options available in the General section. Let's shortly these options in detail:  

Options Description
Discard old builds If we prefer discarding the old builds while initiating a new build, use this option.
GitHub Project If you have source code in GitHub and want to use it in your Jenkins Job, use the GitHub Project option. When selecting this opinion, ensure that you specify the GitHub URL.
This project is parameterized This option allows you to create builds with different parameters that would be passed during run time. Every parameter will have a specific name and value.
Throttle builds Choose the Throttle Builds option when working on a project with a minimum time required between builds based on the expected maximum rate.
Disable this project Choosing this option will disable the project you are currently working on. Simply put, no new build of this current project will get executed.
Execute concurrent builds if necessary This is an additional option you can use to execute multiple builds of this project in parallel.

Once you add the description, let's move to the next section, "Source Code Management". 

Source Code Management

This section allows you to specify the source code that Jenkins Jobs will use to run builds. Jenkins also allows you to use other source code like SVN, Perforce, and many more. However, you need to install additional plugins to use other options in the Jenkins job configuration. By default, you will find two options available in the Configuring Source Code Management section: 

  • None 
  • Git

If you choose None, you will not to asked to add any further detail, and we are good to proceed. 

Alternatively, there is an option to use source code from Git. Jenkins allows source code to be uploaded in the Git version control tool.  When selecting Git as your preference, you will be asked for the repository URL. 

Follow these steps if you prefer to use source code from your Git repo: 

  • Step 1: Select the Git option. 
  • Step 2: Add the repository URL you want the Jenkins Job to use. 
  • Step 3: Save the changes.

After completing the source code management, we will next check the Jenkins Build Triggers option. 

Build Triggers 

Before the Jenkins build step, triggering the job is essential. Building triggers in Jenkins allows you to execute a job on every occurrence. Simply put, any time there is a change in the source code, Jenkins automatically triggers a build with the most recent update.

In the Jenkins Build Triggers option, there are multiple options available. Let's understand each in detail:

Options Description
Trigger builds remotely Choose the triggered builds remotely if you need to trigger new builds using a dedicated URL.
Build after other projects are built Using this option, a new build gets triggered only after other builds are run successfully.
Build periodically If you choose to run builds periodically, choose this option. Ensure that you specify the time you want the build to start.  
GitHub Pull requests Using this build trigger option allows for integration with GitHub Pull Requests and Issues activities. In addition, it launches runs as output.
GitHub hook trigger for GITScm polling Use this option if you need to execute your builds with the help of GitHub webhooks.
Poll SCM Similar to Jenkins Build Periodically build trigger option, we need to specify a timer for Poll SCM. However, the SCM in Jenkins option executes build only when there is any code change during that time.

Jenkins Job Scheduler

Jenkins also provides an option to schedule our Jenkins Job as per our needs. When choosing the Jenkins schedule build option, you have to specify when the build starts. For instance, in our tutorial, we use the Build Periodically option that will trigger the build per the minute specified.

Polling the SCM

Similar to the Build Periodically option, there is another commonly used build trigger option called Jenkins SCM or Poll SCM. Using this Jenkins schedule job option, you need to specify the time you want the build to trigger. Remember, this option will execute build only when any changes are made in the source code during that instance.

Builds

In this section, we will walk through Jenkins Builds. As we are using the basic code using the Windows batch command, let's use the "Execute Windows batch command" option:

Once you click on the above option, a text area will appear where you will be asked to write the command. Specify the command you want the Jenkins Jobs to take as inputs. Once done, click on Apply and then Save the changes as shown:

You will see a confirmation from Jenkins that the changes you made are successful and Saved:

In addition, other Build Trigger options are available for use. Let’s understand each in detail:  

Options Description
Execute Windows batch command If you want to run a Windows batch script to build your project, use the Execute Windows batch command. Here, the script runs with the workspace as the current directory.
Execute shell Using this option will run a shell script to build a project. Similar to Execute Windows batch command, the script runs with the workspace as the current directory here as well.
Invoke Ant When you use this option, it specifies a list of Ant targets to be invoked and is separated by space.
Invoke Gradle Script Consider using this build if you are working on a project where Gradle is in use. Jenkins triggers Gradle with a specific set of switches and tasks.
Invoke top-level Maven targets If you are working on a project where Maven is used as the build system, consider using Invoke top-level Maven targets. Jenkins triggers Maven with a specific set of goals and options.
Run with timeout If a build fails to complete in a specified time, then that particular gets terminated and marked as aborted. If you are using the Run with timeout option, the default time is at least 3 minutes.

Maven Build Steps

Maven is another build tool that we can integrate with Jenkins. We have an option in Jenkins to connect Maven Build with our project. The integration goal is to quicken the build process. Follow these steps to start Jenkins Maven Build.  

Step-1: Navigate to the Jenkins dashboard and go to Manage Jenkins.

Step-2: Go to Global Tool Configuration.

Step-3: Under Maven, click on add maven.

Step-4: Uncheck install Maven and specify the path.

Step 5: Apply and Save the changes. 

Are you interested in learning Maven and Jenkins parallelly? Enroll yourself with KnowledgeHut’s Jenkins Certification Course and get trained by experts. Besides offering the best Jenkins course material, we also offer Maven training to help you strengthen your DevOps skills. Contact us to learn about our training and offerings. 

How to Run Jenkins job?

So far, we have discussed the necessary configuration. Next, we will be good to run Jenkins build jobs. Based on the configured code in the previous step, it's time to execute them and see Jenkins in action. Regardless of your choice, whether you have configured the code by uploading a Git repository URL or merely written codes manually, the job will run anyways. Once the job is executed, you can check the build's status and verify whether it was a success or a failure. 

Use the following steps to run the job manually: 

Step 1: Choose the job you want to run and click on the "Build Now"  section as shown below:

Step 2: On clicking on the Build Now option, the build will get initiated. You can also refer to the Build history to check the list of builds as shown below:

Step 3: Once the build is complete, you can check the build results and verify on the console output screen.

In our example, the build ran successfully. Therefore, the final status of the job is shown as SUCCESS. If there is any bug in the code, the build will fail. If you see a build has failed, investigate the issue and troubleshoot it to get the error fixed.

Congratulations and creating a Jenkins Job successfully. Next, we will learn to trigger another job in Jenkins post-build. 

How to trigger another job in Jenkins post-build?

Running a single job in Jenkins is great. However, there are times when we need to run multiple jobs one after another. This is common if you have a big or complex project. When working on such projects where there is a need to run multiple jobs, Jenkins outperforms automation servers. You can trigger Jenkins builds in a very sophisticated and tech-savvy way. 

Whether the jobs you want to run are dependent or independent of each other, Jenkins build triggers take care of all. Suppose the jobs you want to run depend on each other, and you wish to continue to run the second job upon completion of the first. On the contrary, if the jobs are independent, you want to continue running the second only when the first is completed.  For handling such requests, Jenkins is highly effective and efficient.  

Let’s understand how to trigger the Jenkins job in post-build. Follow the below steps to implement it: 

Step 1: Go to the Jenkins dashboard and navigate to the previous job we have built.

Step 2: Next, go to the configuration section of Demo_Jenkins_Jobs. After that, go to the Post-build actions as shown:

Step 3: On clicking on the Add post-build action dropdown, you will see a list of available options. Select the option "Build other projects" and proceed:

Step 4: Name the project "Demo_Jenkins_Jobs"  inside the "Projects to Build"  textbox. Next, you will see the option “Trigger only if the build is stable.” Select the option and click on Save to continue.

You can go through other available options to explore your knowledge. For simplicity, let's stick with the default option, i.e., Trigger only if the build is stable.  

Step 5: Once you have saved the changes, you will see a newly created Downstream project as shown below:

Step 6: Next, click on the "Build Now"  option to start running the job.

Step 7: Upon completion of the first job, the second job will commence. You can differentiate the two jobs by their project location. i.e., upstream and downstream.

Step 8: Post execution, you can see the build results in the console output. The text "Started by upstream project"  validates that this job was automatically started after successfully executing the first job.

Conclusion

Jenkins has become a key player in the DevOps industry. With the explanation to build Jenkins Jobs from scratch, you can create jobs comfortably. If you are a beginner in DevOps, we suggest you try creating Jenkins jobs following the steps discussed in this tutorial. Once you master the basics, the following strategy must apply to Jenkins in real-world projects. Moreover, you can explore online resources and deep dive into Jenkins. 

Though we have reached the end of the tutorial, this must not be an end to our Jenkins learning journey. Use the concepts discussed to try building Jenkins jobs yourself and experiment with new things. As a one-step forward, we suggest you start building multiple jobs, or maybe creating a pipeline will be a great move. In addition, you can try integrating with Maven or any other comprehension tool to streamline your builds and level up your learning game. 

Happy Computing!

Frequently Asked Questions (FAQs)

1. What is the purpose of the Jenkins job?

2. How are jobs created in Jenkins?

3. What is a pipeline job in Jenkins?

4. What are the job types in Jenkins?

Mayank Modi

86 articles published

Get Free Consultation

+91

By submitting, I accept the T&C and
Privacy Policy

Suggested Blogs