0% found this document useful (0 votes)
24 views23 pages

Jenkins Guide

The document provides a comprehensive guide on installing and configuring Jenkins on Windows, including setting up email notifications, creating jobs, and managing roles and responsibilities. It covers various exercises such as creating automation builds, running Java programs, and establishing a delivery pipeline. Additionally, it explains the master/slave architecture for Jenkins and how to create and manage nodes for efficient job execution.

Uploaded by

weslians2018
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views23 pages

Jenkins Guide

The document provides a comprehensive guide on installing and configuring Jenkins on Windows, including setting up email notifications, creating jobs, and managing roles and responsibilities. It covers various exercises such as creating automation builds, running Java programs, and establishing a delivery pipeline. Additionally, it explains the master/slave architecture for Jenkins and how to create and manage nodes for efficient job execution.

Uploaded by

weslians2018
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Go to https://jenkins.

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.

You can find Jenkins.msi ..click on it – it will start installation.

Click all the buttons until you get Finish button, no need to change any default installation instructions.

Click Finish button. The following screen will appear.

You can open Jenkins from the URL : http://localhost:8080/login?from=%2F

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.

Setting up admin password :


Go to the folder : C:\Program Files (x86)\Jenkins\secrets\
You can find the file named : initialAdminPassword

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

Email-ext Template Plugin

Email Notification Plugin

To update the security in your google account

• Login to Gmail.

• Access the URL as https://www.google.com/settings/security/lesssecure


apps

• Select "Turn on”

Default SMTP Settings for 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:

• Gmail SMTP server address: smtp.gmail.com


• Gmail SMTP username: Your Gmail address (for example, example@gmail.com)
• Gmail SMTP password: Your Gmail password
• Gmail SMTP port (TLS): 587
• Gmail SMTP port (SSL): 465
• Gmail SMTP TLS/SSL required: Yes

ACTION : Manage Jenkins à Configure System àGo down àEmail Notification –Advanced

Provide all the necessary details and test email notification.

A ut

POP – Post Office Protocal

IMAP – Internet Message Access protocol

SMTP – Simple Mail Transfer Protocol


To Know: SMTP Information : https://serversmtp.com/pop-and-smtp/

Exercise 1 : Simple Job Creation :

Jenkins Dashboard à New Item à Enter an Item name à My Second JobàFreestyle Project à OK

You can see 4 Tabs during Job creation:

àGeneral

àSource Code Management

àBuild Trigger

àBuild Environment

àBuild

àpost-build actions.

BUILD: Add Build Step (Drop Down) à Execute Windows Batch Command à

Write Windows batch commands

Ex : echo “ This is my sample Jenkins job : %date% : %time% “

You can lead to the following screen

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

Press Build Now.

Click blue button on under Build History.

Click on Console Output. You can find Outcome of your Windows Commands.

Knowledge:

Note : The following are some of Windows commands.

Some basic commands of batch file


• echo – Prints out the input string. It can be ON or OFF, for ECHO to turn the
echoing feature on or off. If ECHO is ON, the command prompt will display the
command it is executing.
• cls – Clears the command prompt screen.
• title: Changes the title text displayed on top of prompt window.
• EXIT – To exit the Command Prompt.
• pause – Used to stop the execution of Windows batch file.
• :: – Add a comment in the batch file.
• COPY – Copy a file or files

URL : https://www.geeksforgeeks.org/writing-windows-batch-script/

Exercise 2 :

Automation Build test :

Jenkins Dashboard à New Item à Automation Build test àFreestyle Project à OK

Project Name: Second Job

Description: This is my Automation build testing

BUILD: Add Build Step ( Drop Down) à Execute Windows Batch Command à

Write Windows batch commands

Echo “this is my second job that gets triggered automatically in every single minute : %date% :
%time% “.

Go to BUILD Triggers

Select – Build Periodically OPTION

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.

Click on BUILD ICON à Console Output.

Examples:

# 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 *
Exercise 3 : Defining Roles and Responsibilties in Jenkins :

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

Step 1: We have to download the plugins

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.

Use always: Install without restart for all Plug-in installations.

Occasionally, it is better to restart your Jenkins to work properly for small jobs not necessary.

Then go and about installed plugin

Goto à Configure Global Security and there will be Authorization heading like following

Authorization à You can find “Role based Strategy “ ..enable and save it.

Save

Then go to Manage Plugins

Select Manage and Assign Roles


Manage Roles: For creating the roles for the project

Assign Roles : Assigning the users to the project.

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.

Now I created a Role, now let us start creating Users.

Creating Users :

Select the Plugin – Manage User à Create User à UserName/pwd


Note : Keep UserName/Pwd handy for the users

Assigning the Role to the New User :

Manage Assign RolesàAssign Roles

Save the Role:

Logout and Login as a new a user and experience the change of your role.
Exercise 4 : Creating some JAVA Programs and executing.

1. Create a Folder Java Programmes


2. Open a Note Pad à Save the file with .java
3. Copy some sample programs as below
4. Go to command prompt
5. Go to path, where you stored your programmes
6. First compile the programme using javac ( You can find class file will be created in the same
folder)
7. Ex : javac HelloWorld.java
8. Execute the program using command java classfilename( without extension)
9. Java HelloWorld

Progamme 1 :

class Simple {

public static void main(String args[]){

System.out.println("Hello World");

Program 2 :

public class Sample {

public static void main(String[] args)

for (int i=1; i<=10;i++)

System.out.println(" My Name is Bala..." +i);

}
}

public class AddTwoNumbers {

public static void main(String[] args) {

int num1 = 5, num2 = 15, sum;

sum = num1 + num2;

System.out.println("Sum of these numbers: "+sum);

Sample Prorammes :

https://beginnersbook.com/2017/09/java-examples/

Exercise : 5

Push all the programs to Github … Use Git User Guide.

Exercise : 5 :

Running Java Programs from Jenkins Build :

Jenkins Dashboard à New Item à Automation Build test àFreestyle Project à OK

Project Name: Running Java Programmes from Local

BUILD àExecute Windows Batch Command

Step1 : Put the PATH

Ex : C:\Java Programs

Javac javaprogram.java

Java javaclassfile

BUILD from Dashboard

View the console output.

Exercise : 6

Push all the programs to Github … Use Git User Guide.

Exercise : 7

Connecting Github to Jenkins :


Install Plug in Git Plugin

Create the project

Jenkins Dashboard à New Item à Automation Build test àFreestyle Project à OK

Project Name: Running Java Programmes from Git

Source Code Management : Git

Repository URL : Ex : https://github.com/grbalas/Java-Programs1.git

BUILD TRIGGERS: Select Poll SCM

Provide Schedule : * * * * * ( for every minute) ( Check every minute in Git and if there is a change, it
will update)

BUILD : Execute Windows batch command

Ex : cd C:\Java Programs

javac Demo.java

java Demo

java Simple

APPLY and SAVE

Exercise 8 : Running builds remotely.

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

If you paste above URL in any browser window…Build will run

Note : Localhost:8080 – If Jenkins installed in your local machine

You can also give ip address of any computer in place of local host Ex : 9.82.32.3:8080

Ie..9.82.32.3 is iP address of server where your Jenkins in installed.


Exercise 9 : Creating Delivary Piplelines using simple programmes.

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.

Create these jobs in sequence of Sample BuildàSample Deployà Sample Test

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.

Select Trigger only if build is stable

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.

Step 2 : Install Delivery pipeline plugin

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.

Manage Jenkins àAvailable à Delivery Pipe line plugin and install

Step 3 : Go to Delivery Pipeline view

Jenkins Dashboard à TestView à Select Delivary Pipleline View

View Name : Test Delivary Pipleline View

Save OK

Go Down à Add Component à Select Sample Build Job … Name : Sample Build

OK

You can see the view of 3 Jobs due to dependency.

You can see Full screen view from Left Nav bar

Come back

Go to Edit View
Go to help and read all the items

Check on : Number of pipe line instances per pipeline

Enable start of new pipeline build

Show total build time

Enable rebuild and see the views

This is about Delivary Piple line

Exercise 10 : Some important Configuration Settings :

System Messages on the Dashboard:

Manage Jenkins à Configure System à System Message à this is Bala’s System ..apply and save (
This is a Text Message)

you can this message on Manage Jenkins page.

You can also give HTML messages over here…

To do that, go to Manage Jenkins – Configure Global Security à Markup Formatter

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.

Master /Slave Architecture :

Partition your hard disk into D and E Drives :

How to do that ..

https://www.youtube.com/watch?v=_HgjasKuOBw

File Explorer – right click -This PC àchoose Manage à Computer Management Window appears

Select StorageàDisk Management

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.

Go to Configure Global Securityà Agents .. by default, it is Disabled…. Now make it Random.

Creating Slaves:

Step 1: Create a folder in D: drive as MACSLVVE

Path is going to be: D:\MACSLAVE

Step 2: Creating new nodes in Jenkins

Go to à Jenkins Portal: http://localhost :8080

Manage Jenkins à Manage Nodes-> on the left side -- > New node
Name it – MAC-NODE à Select Permanent Agent.

Inside fill the following

Nameà MAC-NODE ( by default it will be there ..no need to change)

Descriptionà MAC-NODE (same as above)

Remote root Directory à D:\MACSLAVE ( You already created a folder in D: drive)

Labels à MAC-NODE (same as Name and Description)

Usage à Select Only build jobs with label expressions matching this node.

Launch Method à Select Launch Agent by connecting it to the master.

Do not change any other default settings .. save the changes with SAVE button at the end of the
page.

SAVE.

You can see


Click on MAC-NODE

You can lead to the following page :

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.

Then go to command prompt …get into D:\MACSLAVE

Then paste the command as mentioned in your Jenkins node page.


java -jar agent.jar -jnlpUrl http://localhost:8080/computer/MAC-NODE/slave-agent.jnlp -secret
2a617580f108c2fedf100067b09e42395dd6f204791fb6e7c183c07bedb77482 -workDir
"D:\MACSLAVE"

Once it gets executed…it will show as .. Connected at the bottom.

You need to keep this command prompt open to keep agent to run.

Now D:\MAC-NODE is running as a Node ( like other machine).

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

Create a new project – Delegate Job à Free style project à OK

Under General tab :

Select Label Expression: MAC-NODE ( This is the place, where you are instructing by giving label as
node name)

Build -> Add Build àExecute Windows batch command

.>>echo “ This is delegated to Agent “

Save

Run Job and see the console out put.

Console Output would be as follows


The above message clearly says that job ran at MAC-NODE and not in master slave.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy