Grab Deal : Flat 20% off on live classes + 2 free self-paced courses! - SCHEDULE CALL

- DevOps Blogs -

The Truth About Jenkins Configuration Is About To Be Revealed



Introduction

Just to revise, In the last blog we study about different Jenkins management properties like user, security, plugin and credentials. Now, let’s proceed to check how to configure different tools in Jenkins. Mainly, for any CI/CD process, we require to configure 

  • Language (JAVA/C/Ruby)
  • SCM (GIT Configuration/SVN configuration)
  • Build Tool (Maven/Gradle/ANT)

Basically, Jenkins configuration for this require two pages mainly

  • Manage Jenkins → Configure System
  • Manage Jenkins → Global Tool Configuration

So, Let’s start

DevOps Training & Certification Course

  • No cost for a Demo Class
  • Industry Expert as your Trainer
  • Available as per your schedule
  • Customer Support Available

JAVA / JDK Jenkins Configuration

  1. JAVA configuration is required because of multiple reasons

    • If multiple JAVA installed on a machine and your project requires specific JAVA to compile
    • If JAVA installed on the default location
    • If there is a new Jenkins machine where you want to install JAVA as per requirement during run time.
  2. First, proceed to Jenkins → Global Tool Configuration, there is one block “JDK”. Click on “Add JDKJDK Jenkins Configuration

  1. It will explode to several Jenkins configuration fields for JAVA:

DK Jenkins Configuration2

  • Name -- User-defined name to be used in Jenkins jobs
  • Install automatically -- If Selected, “Add Installer” option will be available. Several options available for Installer

DK Jenkins Configuration3

I. Extract *.zip/*.tar.gz

DK Jenkins Configuration

Label is an optional field, Nodes which validate this expression will be allowed to install. Enter the zip/tar.gz URL to download from and the “Subdirectory” field is also optional where to unpack the archive and download tool.

II. Install Oracle JAVA SE Download Kit from the website

Run Batch command

Select the Version, Agree to Terms, Login to Oracle and you are done !!

III. Run Batch command

Run Batch command

The label field is optional to restrict the command to run on nodes validating this label. The command is the command used to run batch scripts for installation. Tool Home is resulting home directory of installed “tool

IV. Run Shell command

Same as “batch” except it will execute a shell script.

c. If “Install Automatically”, not selected

Install Automatically

Just provide JDK name (User Defined) and JAVA_HOME (Directory where JAVA is installed). If multiple versions are installed, Add different JDKs with different names to re-use that name in required Jenkins jobs.

  1. After Configuration, let's see it through a demo. Create a new project by going New Item → Freestyle Project

Install Automatically

  1.  You will be able to see JDK selection configuration only when multiple JDK configurations. For this Demo, I have created two JDK with name JDK8 and JDK9

After Configuration

  1. It will have three drop-down:

    1. System
    2. JDK8
    3. JDK9

Let’s test console output by selecting each. In Execute Shell block under “Build Step”, write 

java -version

  1. Check Console output. It will print system provided JAVA details

  1. Select JDK8 from the list, Save and “Build Now

  1. Now, Select JDK9

  1. Let’s take another demo of using pipeline jobs. Update Jenkinsfile with the appropriate tool you want to use and it will execute accordingly as per requirement. Create a “Pipeline” project. 

  2. Select “Pipeline Script” and write sample Jenkinsfile

Pipeline Script

  1. Build now and check Console output:

Pipeline Script

GIT Jenkins Configuration

Git configuration in Jenkins is quite easy. Git configuration in Jenkins is required to integrate Source Code with our CI/CD process.

  1. We will be using GIT as an SCM tool, because of its worldwide usage. In GIT, source code is managed and is an integral part of CI/CD set up. As per the process, source code should be taken from the repository and then required artefacts build and deployed to the required environment. 
  2. For this, let's configure Jenkins. Install “Git Plugin” In Jenkins 

  1. Once Installed, check the Jenkins configuration for JOB, you will be able to see “Git” as an option in Source Code Management section for git configuration:

Source Code Management

  1. Let’s try the usage with a demo. Create a new freestyle project. Select “Git” in Source Control Management.

Source Code Management

  1. Enter “Repository URL”. Credentials required to connect, if present, then select from list otherwise Click “Add” to add credentials. “Branch Specifier” by default is “master”, but you can mention another branch also if you want to build from that.

Source Code Management

  1. Click “Build Now” and check console output

Source Code Management

As you can see, Job performed multiple git commands executed using credentials provided to connect and checking out the git repository. So, our git configuration is working. You can check from Workspace also, whether everything is checked-out or not. 

  1. Some steps to troubleshoot:

  • It can give errors for not being able to connect because of invalid credentials - Check credentials you want to connect and it will be resolved.
  • SSL error -- If your repository is configured with “https”, provide correct SSL certificate or make sslVerify=false
  • Error performing git.exe -- git is not installed in the machine where the job is running. Install git manually or go to “Global Tool Configuration” and configure for “GIT” also, like its done for JAVA

Some steps to troubleshoot:

  1. Let’s demo usage in pipeline jobs, Create a new pipeline(or multibranch pipeline) job, Select “Pipeline script from SCM” to read Jenkinsfile from SCM to perform build, test, deploy stages on the code present in the repo.

new pipeline

Fields are the same, it will checkout code from that repository, search for Jenkinsfile at root path and then execute it. 

  1. Save → Build Now and check console output. You will see several stages perform its operation. Dashboard view would be:

 stages perform

  1. More git configuration management is required if you want to perform various operation depending on your job or requirement

  • Job should trigger for any push(create/update of code/branch) to the repository.
  • Job should trigger whenever new Pull-request got created/changed
  • Job should trigger after SCM polling is completed.
  1. You must be working on one of the repository management tools from Github, Gitlab or Bitbucket. Different plugins will be available for these tools depending on the task. It will be the same for all but here, we will be discussing Github.

  2. Install “Github Branch Source Plugin” which will help you in Multibranch Pipeline jobs, whenever any push or PR is created. This is required to check that your PR/Branch is in working condition and will not break the “master” code. 

  3. You can get more information in Git workflows documentation and will create more settings about these types of jobs in coming blogs.

  4. Install “Github Plugin” for normal integration with Jenkins

  5. Proceed to Manage Jenkins → Configure System. Search for Github

Provide Github Servers, if any or let it be just like that. It is required if you want your Jenkins to manage webhooks from Github server.

  1. In your Jenkins job also, you will be seeing Github for git configuration

  1. Under Build Triggers, to trigger hook when SCM polling finished

  1. Github webhooks will be covered for “Multibranch pipeline jobs” and will be explained in the next blog.

Maven/Gradle Jenkins Configuration

Now, the third most important thing is to build tool configuration, and most popular build tools across organizations are:

We will discuss the Maven configuration. But to note, the configuration of both the tools are the same, it's just like two different tools, so different plugins name and different configuration. Both can be replaceable on the same grounds.

  1. Plugin required for Maven Install is from Manage Jenkins → Manage Plugins

    a. For Maven configuration

Manage Plugins

b. For Gradle

  1. Add tool details in Manage Jenkins → Global Tool Configurations

Global Tool Configurations

Both the tools configured on similar lines like we installed JAVA like we set up GIT. Here, I did Maven configuration with the name “M3” and will use it in my Jenkins jobs. In this also, if Installer selected, then for maven install, add required installer. For different maven options, add respective Maven Install and use.

  1. For maven configuration, proceed to Manage Jenkins → Configure System

maven configuration

Place MAVEN_OPTS which will be available globally to the whole Jenkins. The default location of the Local Maven repository is ~/.m2/repository but can be entered locally to the workspace of the executor of the node. 

  1. Let’s start with a demo and will see configurations from Job’s configure window as well.

  2. Create New Freestyle Project → Configure. Select “Invoke top-level Maven targets” from Build step for Maven(“Invoke Gradle Script” for Gradle)

maven configuration

  1. Select 

  • Maven Version, we named it as M3 in “Global Tools Configuration”, 
  • Goals which you want to execute -- clean install. As we know maven install will run all default goals like compile, package etc.
  • POM -- the location of pom.xml file if other than in project root directory.
  • Properties -- If you want to specify some properties with mvn commands
  • JVM options -- if any Xmx or Xms variable
  • Similarly, provide the location of settings or Global settings file.

By default, these two settings compulsory

  1. Now, it will execute “mvn clean install” on the source code pom.xml file mentioned in Git repo. Click Save → Build now and check console output:

mvn clean install

Check the steps: Source code is checked-out, executed maven command “mvn clean install” as specified in the configuration.

  1. Let’s include Maven configurations in our Jenkinsfile. Create a new pipeline job. Sample Jenkinsfile will look like:

 Maven configurations

It will use JDK8 and M3 variables(created using maven install) which are set up in “Global Tools Configuration” and that will be used during the run. Click Save → Build Now

  1. Check Console output. I am giving screenshot having both the versions defined and stages:

Console output

  1. A PIpeline is completed successfully with all stages completed. This is how to build tool used in pipeline jobs

Conclusion

Now, we configured the basic necessary tools required for the CI/CD process like git configuration management, java configuration and maven configuration. Please let me know if you faced any issue while configuring it. In Next blog, we will set up a full-fledged multibranch pipeline job. See you soon !!

fbicons FaceBook twitterTwitter google+Google+ lingedinLinkedIn pinterest Pinterest emailEmail

     Logo

    JanBask Training

    A dynamic, highly professional, and a global online training course provider committed to propelling the next generation of technology learners with a whole new way of training experience.


  • fb-15
  • twitter-15
  • linkedin-15

Comments

Trending Courses

Cyber Security Course

Cyber Security

  • Introduction to cybersecurity
  • Cryptography and Secure Communication 
  • Cloud Computing Architectural Framework
  • Security Architectures and Models
Cyber Security Course

Upcoming Class

-1 day 19 Apr 2024

QA Course

QA

  • Introduction and Software Testing
  • Software Test Life Cycle
  • Automation Testing and API Testing
  • Selenium framework development using Testing
QA Course

Upcoming Class

-1 day 19 Apr 2024

Salesforce Course

Salesforce

  • Salesforce Configuration Introduction
  • Security & Automation Process
  • Sales & Service Cloud
  • Apex Programming, SOQL & SOSL
Salesforce Course

Upcoming Class

7 days 27 Apr 2024

Business Analyst Course

Business Analyst

  • BA & Stakeholders Overview
  • BPMN, Requirement Elicitation
  • BA Tools & Design Documents
  • Enterprise Analysis, Agile & Scrum
Business Analyst Course

Upcoming Class

-1 day 19 Apr 2024

MS SQL Server Course

MS SQL Server

  • Introduction & Database Query
  • Programming, Indexes & System Functions
  • SSIS Package Development Procedures
  • SSRS Report Design
MS SQL Server Course

Upcoming Class

-1 day 19 Apr 2024

Data Science Course

Data Science

  • Data Science Introduction
  • Hadoop and Spark Overview
  • Python & Intro to R Programming
  • Machine Learning
Data Science Course

Upcoming Class

6 days 26 Apr 2024

DevOps Course

DevOps

  • Intro to DevOps
  • GIT and Maven
  • Jenkins & Ansible
  • Docker and Cloud Computing
DevOps Course

Upcoming Class

5 days 25 Apr 2024

Hadoop Course

Hadoop

  • Architecture, HDFS & MapReduce
  • Unix Shell & Apache Pig Installation
  • HIVE Installation & User-Defined Functions
  • SQOOP & Hbase Installation
Hadoop Course

Upcoming Class

0 day 20 Apr 2024

Python Course

Python

  • Features of Python
  • Python Editors and IDEs
  • Data types and Variables
  • Python File Operation
Python Course

Upcoming Class

-1 day 19 Apr 2024

Artificial Intelligence Course

Artificial Intelligence

  • Components of AI
  • Categories of Machine Learning
  • Recurrent Neural Networks
  • Recurrent Neural Networks
Artificial Intelligence Course

Upcoming Class

7 days 27 Apr 2024

Machine Learning Course

Machine Learning

  • Introduction to Machine Learning & Python
  • Machine Learning: Supervised Learning
  • Machine Learning: Unsupervised Learning
Machine Learning Course

Upcoming Class

-1 day 19 Apr 2024

 Tableau Course

Tableau

  • Introduction to Tableau Desktop
  • Data Transformation Methods
  • Configuring tableau server
  • Integration with R & Hadoop
 Tableau Course

Upcoming Class

0 day 20 Apr 2024

Search Posts

Reset

Receive Latest Materials and Offers on DevOps Course

Interviews