Jenkins
Jenkins is an open source automation server written in Java.
Jenkins helps to automate the non-human part of software development process, with continuous
integration and facilitating technical aspects of continuous delivery
Jenkins focus on Build and test software project continuously and monitoring externally run jobs
Software builds can be triggered by various means, for example by commit in a version control
system, by scheduling via a cron-like mechanism and by requesting a specific build URL. It can
also be triggered after the other builds in the queue have completed. Jenkins functionality can be
extended with plugins.
Why Jenkins?
Benefits of Jenkins
Catch issues
faster
CI leads to CD
allowing you Everyone can
to deliver see what’s
software more happening
rapidly
Keep the build Automate the
fast build
Installing Jenkins
1. Go to URL : https://jenkins.io/download/
2. Downlaod Jenkins for Windows. We will use Jenkins Long Term Support(LTS) release.
3. Unzip the files. Double click on Jenkins installer
4. Follow the instruction as below screens
5. After click on ‘Finish’ button, your default browser will auto open with url –
http://localhost:8080/login?from=%2F displaying information of your Jenkins default
administrator password
6. Copy paste the password and click Continue button
7. Click on install suggested plugins
8. This will start downloading and installing default suggested plugins
9. Create first Admin user. This will be your first user created administrator account. So make sure
you keep your administrator user name and password some where safe so when you login next
time you know your administrator username and password.
10. Click on Save and Finish button
11. You have successful completed Jenkins installation!!!
12. Click on start using Jenkins
13. Open chrome browser and type following and hit enter
Localhost:8080
It will open Jenkins window and ask you to enter your username/password!!!
Jenkins administration & Configuration
Manage Jenkins
Click on “Manage Jenkins”
Click on “Configure System”
You can configure work space root directory, Git specific settings and Email notification
Global Tool Configuration
Configure JDK, provide JDK name and its path. Also make sure you uncheck automatically
install new Java version
Configure Maven, Maven name and its path. Also make sure you uncheck automatically
install new Maven version
Similarly you can configure Ant, Git, Docker or any other tools
Configuring Jenkins Security
Click on “Manage Jenkins”
Click on “Configure Global Security”
Check enable security option
Access Control: Jenkin’s own user database
Authorization: Matrix based security
Jenkins Plugins management
Click on “Manage Jenkins”
Click on “Manage Plugins”
Plugins are the primary means of enhancing the functionality of a Jenkins environment to
suit organization- or user-specific needs. There are over a thousand different plugins which
can be installed on a Jenkins master and to integrate various build tools, cloud providers,
analysis tools, and much more.
Plugins can be automatically downloaded, with their dependencies, from the Update Center.
The Update Center is a service operated by the Jenkins project which provides an inventory of
open source plugins which have been developed and maintained by various members of the
Jenkins community.
What is GIT?
Git is a free and open source distributed version control system designed to handle everything
from small to very large projects with speed and efficiency
To track changes in files/folders
To collaborate in teams
Git stores the data in terms of “snapshots”. Snapshots is like a revision
When we comit in the GIT, it stores the data in terms of set of snapshots. Git only copy the files in
which changes are done
Two types of version Control systems
Centralized Version Control Distributed Version Control
Git Workflow
GitHub
A website to upload repositories
It provides backup e.g. it stores in cloud.
Provide visual interface to your repositories
It makes collaboration easier with other people
Git is not the same as GitHub
Installation of Git
https://git-scm.com/downloads
Click on Windows (Download installer based on 32 bit or 64 bit Operating System)
Commands Description
git config --global user.name “[firstname set a name that is identifiable for credit when
lastname]” review version history
git config --global user.email “[valid-email]” set an email address that will be associated with
each history marker
git init initialize an existing directory as a Git repository
git clone [url] retrieve an entire repository from a hosted
location via URL
git status show modified files in working directory, staged
for your next commit
git add [file] add a file as it looks now to your next commit
(stage)
git reset [file] unstage a file while retaining the changes in
working directory
git commit -m “message…> Commit code in your local Git repository
git push [URL] [branch] Transmit local branch commits to the remote
repository branch
Creating a GIT repository
Two ways you can create GIT repository
1: Create GIT repository in an existing project
2: Create a clone of entire GIT repository from a remote server
Maven Jenkins configuration
https://jenkins.io/solutions/java/
TestMG Maven Integration
Add following in POM.xml file
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
Create a profile in POM.xml file for batch execution of test cases using different testng.xml
file
<profiles>
<profile>
<id>Sanity</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>san_testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Jenkins Execution using batch files
Go to root folder of your project on command prompt
Create a lib folder and copy all jar files. If you are using Selenium and TestNG in your project,
make sure you copy all Selenium and TestNG specific jar files.
Set the classpath example below
set classpath=C:\Users\Naresh\oxygen-workspace\Week7\bin;C:\Users\Naresh\oxygen-
workspace\Week7\lib\*;
Execute the testng.xml file as below
java org.testng.TestNG testng.xml
This will execute your test case at command prompt using testng.xml file
Making the batch file
Open a notepad and type below
Java -cp bin;lib/* org.testng.TestNG testng.xml
(make sure you type exactly as above)
Save the file in your project root folder with name as “testrun.bat” . make sure you use “”
surrounded with file name so that will convert your file into a windows batch file
Just double click the testrun.bat file. This will execute your test case