Jenkins Guide
Jenkins Guide
io/
Do not press Download in the next page. Please go down to the in the same page, you can find 2
Options over there Long-term Support (LTS), Weekly
There are the versions which are available for Jenkins so when you scroll down you will see different
versions of Jenkins one is the LTS version and other is the weekly release so we are going to use the
long term support version and the latest version is 2.190.1 and in here we are going to choose the
windows option so here you will see the windows option.one thing you need to keep in mind is when
you are installing Jenkins on Windows it is good to run Jenkins as a service so it starts automatically
without requiring any user to log in the easiest way to install Jenkins on Windows is by using
Windows.
Click all the buttons until you get Finish button, no need to change any default installation instructions.
For any reason if you don’t get the screen…you can go to any browser and put the URL :
http://localhost:8080 .. as Jenkins will be at port 8080 by default. where you can see the below
screen.
Open the file in NOTE PAD : you can see some password like : 263a96e8c1ef4d389665fe4bf3ccdeb6
Paste the same password in above window…that can lead to the following screen
This will install many plugins, some of them may give error due to as your system don’t have that
software, nothing to care about those now. Let get install as it goes.
You want to provide userID/pwd..once you provide, you will be logged in to Jenkins Wizard as
below..
Configuration Page:
Go to Manage Jenkins :
Email Notification Set up in Jenkins :
Plugins to be Installed:
Plugin
• Login to Gmail.
As you set up an email client to synchronize with your Gmail account, a screen asks for your
Gmail SMTP information. Use these settings:
ACTION : Manage Jenkins à Configure System àGo down àEmail Notification –Advanced
A ut
Jenkins Dashboard à New Item à Enter an Item name à My Second JobàFreestyle Project à OK
àGeneral
àBuild Trigger
àBuild Environment
àBuild
àpost-build actions.
BUILD: Add Build Step (Drop Down) à Execute Windows Batch Command à
Nothing to touch for any settings now…go to the BUILD tab and type some windows command for a
simple job and Save.
Press OK
Click on Console Output. You can find Outcome of your Windows Commands.
Knowledge:
URL : https://www.geeksforgeeks.org/writing-windows-batch-script/
Exercise 2 :
BUILD: Add Build Step ( Drop Down) à Execute Windows Batch Command à
Echo “this is my second job that gets triggered automatically in every single minute : %date% :
%time% “.
Go to BUILD Triggers
Click help icon (?) at the end to understand the set up the time.
Here I am going to use * * * * * (I wanted to build the code in every minute)…then SAVE.
Observe the BUILD HISTORY .. you can see build results automatically after every minute.
Examples:
Creating Roles in Jenkins to control the access levels : Global roles and Project Specific Roles.
Example: Creating a Developer role and give some privileges to use this tool
Manage Jenkins – Manage Plugins – go to tab Available - > search for Role based *
You can find a Plug in called: Role-based Authorization Strategy, which need to be installed.
Occasionally, it is better to restart your Jenkins to work properly for small jobs not necessary.
Goto à Configure Global Security and there will be Authorization heading like following
Authorization à You can find “Role based Strategy “ ..enable and save it.
Save
After adding the role, you need to save the plug-in in the bottom of the page.
Manage and Assign Roles: Global Roles, Project Roles, Slave Roles.
Creating Users :
Logout and Login as a new a user and experience the change of your role.
Exercise 4 : Creating some JAVA Programs and executing.
Progamme 1 :
class Simple {
System.out.println("Hello World");
Program 2 :
}
}
Sample Prorammes :
https://beginnersbook.com/2017/09/java-examples/
Exercise : 5
Exercise : 5 :
Ex : C:\Java Programs
Javac javaprogram.java
Java javaclassfile
Exercise : 6
Exercise : 7
Provide Schedule : * * * * * ( for every minute) ( Check every minute in Git and if there is a change, it
will update)
Ex : cd C:\Java Programs
javac Demo.java
java Demo
java Simple
Go to any project
Configure àBuild Triggers à Trigger Build remotely à Provide security token ( ex: 12345)..copy the
URL given down..
Use the following URL to trigger build remotely:
JENKINS_URL/job/mnp_Job1/build?token=TOKEN_NAME or
/buildWithParameters?token=TOKEN_NAME
Ex : :localhost:8080/job/mnp_Job1/build?token=12345
You can also give ip address of any computer in place of local host Ex : 9.82.32.3:8080
Step 1: Create 3 sample jobs and it create a chain (define upstream and downstream) among them.
Create Sample Build Job with Execute batch command echo “ echo " this is my first build job :
%date% : %time% " APPLY, SAVE.
Create Sample Deploy Job with Execute batch command echo “ echo " this is my first deploy job :
%date% : %time% " APPLY, SAVE.
Create Sample Test Job with Execute batch command echo “ echo " this is my first test job :
%date% : %time% " APPLY, SAVE.
To do, go to
Project Sample Deploy àConfigureà Build Triggersà Select Option Build after other projects are
built àprojects to Watch à type Sample Build job à Apply and SAVE.
Project Sample Test job à Configureàbuild TriggersàSelect Option Build after other projects are
builtàproject to watchà type Sample Deploy Job
Trigger only if build is stable
Now when you run Sample Build Job, it triggers Sample Deploy, which triggers, Sample Test job.
Go to each Job and look for the latest build that ran.
Either you can search in Google about the pipe line plugin , where you can get all the details about
the plug in . Best way is to install from your Available view.
Save OK
Go Down à Add Component à Select Sample Build Job … Name : Sample Build
OK
You can see Full screen view from Left Nav bar
Come back
Go to Edit View
Go to help and read all the items
Manage Jenkins à Configure System à System Message à this is Bala’s System ..apply and save (
This is a Text Message)
By default ..it will be plain text ..you can change it to html format. Ie Safe HTML
Now go to Jenkins Dashboard à Configuration à System Message à type <h1> This is Bala </h1>
Save and exit – you can see HTML format name on the Dashboard.
How to do that ..
https://www.youtube.com/watch?v=_HgjasKuOBw
File Explorer – right click -This PC àchoose Manage à Computer Management Window appears
You can see C Drive Capacity window à right click and select à Shrink volume à 5000 ( for 5 GB)
è You can see 4.88 GB Unallocated. Name it with E or D.. create E Drive and D Drive.
Currently where Jenkins in running is Master Node. For Big projects ..only Master can not handle all
the jobs to run…so, it needs to create some other nodes called slaves to help master.
Here we will be using master in C Drive and Slaves will be in D and E Driver.
To make proper communication between master and slave we need to use JNLP ..Java Net work
Launch protocol, which need to be set up.
To do this.
Creating Slaves:
Manage Jenkins à Manage Nodes-> on the left side -- > New node
Name it – MAC-NODE à Select Permanent Agent.
Usage à Select Only build jobs with label expressions matching this node.
Do not change any other default settings .. save the changes with SAVE button at the end of the
page.
SAVE.
Click on “ agent.jar” hyper link, and download the file into Download directory.
Copy agent.jar file from Download directory and copy in the folder D:\MACSLAVE.
Note : The file name should be “ agent.jar” not as agent(1).jar or agent(2).jar etc.
You need to keep this command prompt open to keep agent to run.
When you go and look at D:\MAC-NODE folder, you can see an additional folder called “ remoting “.
Now let us go to Jenkins dashboard
Select Label Expression: MAC-NODE ( This is the place, where you are instructing by giving label as
node name)
Save