Jenkins setup in Ubuntu + Integrating selenium project

Sonal Dwivedi
Sep 5, 2018 · 8 min read
  • How to download jenkins.war file
  1. Searching “download jenkins war file” in google will give you multiple search results. Open the url “https://updates.jenkins-ci.org/download/war/” which is the official page to download jenkins war file.

2. Click on “permalink to the latest” on that url. It will directly download the jenkins.war file.

Url for downloading jenkins war file
  • How to run/ install jenkins war file

1. Go to the downloads section where jenkins war file is downloaded and copy-paste it a new folder (any drive).

2. Now, install the jenkins.war file through command line.

i. Open terminal where the jenkins war file is placed.

ii. Type “ls” on that folder and checkthat jenkins.war file is available.

iii. Type “java -jar jenkins.war”

Installing jenkins war file

3. It will start initialization process for Jenkins. It will create Jenkins home directory, and other required files in your system. Once you get to see stars in 3 lines (*********), its saying that “Jenkins initial setup is required. An admin user has been created and a password is generated”.

4. Jenkins by-default runs on 8080 in local machine. Go to browser and type “localhost:8080”, press enter. “Unlock Jenkins” screen appears.

If your port 8080 has been already occupied with some other process like Tomcat, Oracle, etc, use your own port number while running jenkins.war file

For http: java -jar jenkins.war –httpPort=9090

For https: java -jar jenkins.war –httpsPort=9090

5. Now paste the password generated in console in “Unlock Jenkins” screen and click on “Continue”

6. After this, it should take you to “Customize Jenkins” screen. Click on “Install suggested plugins”.

7. After this “Getting Started” page should appear. Now it will automatically start installing default plugins. (Make sure you are connected to an active network connection). Let it complete, this will take a few minutes.

8. Now after the plugins are downloaded, it will move to “Create First Admin User” screen.

9. Enter a desired username, password and confirm password. Then, enter your name and valid email address.

Click on “Save and Continue”

10. “Jenkins is ready!” page should appear. Click on “Start using Jenkins”

11. This should take you to Jenkins home page.

  • How to setup the project and install Maven, TestNG plugin
  1. Click on “New item”. This should take you to “Enter an item name” screen.

2. If your project is Maven you will have to download Maven plugin.

Below are the steps to download Maven plugin:

i. Click on “Jenkins” at the top left corner -> click on “Manage Jenkins” -> click on “Manage plugins”-> Click on “Available”. Search for maven in filter section and you should get some maven plugins populated under search.

ii. Select the maven plugins (Maven Artifact ChoiceListProvider (Nexus), Maven Metadata Plugin for Jenkins CI server, Maven Integration, Maven Dependency Update Trigger, Unleash Maven, Maven Release Plug-in, Maven Invoker, Maven Repository Scheduled Cleanup, Maven Info) and click on “Download now and install after restart“.

One by one it will download and install the Maven plugins. You should see “Download successfully. Will be activated during the next boot” and “Success” messages for already downloaded plugins.

3. After downloading all the maven plugins, click on “Restart jenkins when installation is complete and no jobs are running”

4. “Please wait while Jenkins is restarting” screen should appear.

In parallel, monitor your jenkins terminal which has all the console logs of maven plugins download. Don’t close this command prompt otherwise jenkins will stop.

5. In jenkins command line, once you see “Jenkins is fully up and running” statement, you should be able to see “Welcome to Jenkins” screen with username and password textbox in your localhost.

6. Type the username and password and click on “log in”. Now it should take you to “Installing Plugins/Upgrades”. If you see this page click on “Restart Jenkins when installation is complete and no jobs are running”.

You can check that all the maven plugins are now present under Jenkins-> Manage Jenkins-> Manage Plugins-> Installed

7. Now, once maven plugins are installed, click on “Jenkins”→ “New item”. Now you should be able to see “Maven project”.

Write project name as “DemoTestJob” and click on “Maven Project”. Click on “OK”. This should open project detail page under General tab.

Enter project description as:

“DemoTestJob:

Test Automation Suite for Demo App”

8. Don’t select/check anything under “Maven Info Plugin Configuration”.

9. If you don’t have your code pushed to GitHub and your project lies under local Eclipse, check “None” under “Source Code Management”

10. In “Build triggers”, let by-default selection be “Build whenever a snapshot dependency is built”

11. Don’t select/check anything under “Build Environment” and “Pre-Steps”.

12. Under “Build”, you should see “Jenkins needs to know where your Maven is installed. Please do so from the tool configuration.” in red font because Jenkins doesn’t know where Maven is installed in your laptop.

Click on “the tool configuration”. It should open “Global tool configuration” in next tab.

Scroll down and click on “Add Maven”. Enter Name as “TestMaven” and by-default it will have latest version of Maven selected. Click on “Apply” then “Save”. Close the tab.

13. Now go to your eclipse project, copy your pom.xml location and paste it under “Root POM”.

14. Write “clean install” under “Goals and options”. Whenever Maven will trigger the build, it will first clean, install and then execute the testcases.

15. In “Post Steps”, let by-default selection be “Run regardless of build result”.

16. Now to publish TestNG reports, TestNG plugin should be installed. If you check under “Post-build actions” drop down, “Publish TestNG Results” should be present. If this is not present, you have to download TestNg plugin. So for now “Apply” and “Save”.

Go to Jenkins→ Manage Jenkins→ Manage plugin→ Click on Available. Search for testng.

Select “TestNG Results” and click on “Download now and install after restart”.

Let TestNg result plugin get fully downloaded and click on “Restart jenkins when installation is complete and no jobs are running”. Jenkins will be restarted.

You can check that TestNG plugin should be present under Jenkins-> Manage Jenkins-> Manage Plugins-> Installed.

17. After that click on Jenkins→ Click on the project created “DemoTestJob”. Click on configure, scroll to “Post-build Actions” and select “Publish TestNG Results” from drop down. Click on “Apply” and then “Save”.

“**/testng-results.xml”→ Now this will search for “testng.xml” report from any directory (hence, **/).

  • How to trigger Jenkins build:
  1. Now the project is created and configured. Everything is ready and you are good to trigger your build.
  2. Go to your created project (DemoTestJob) and click on “Build Now” and lets see if it launches chrome or not?
  3. After triggering the build, under “Build History”, you can see build number and its status/console output by clicking on the “#<number>”. You will see whatever console logs were generated in eclipse are now displayed under Jenkins console.

It will parse the pom file, then it will check whether there is anything to execute or not.

You should see “clean install” command. It will download some artifacts.

Then you should see “TESTS”.

Then you should be able to see chrome browser launching and thereafter all the tests mentioned in your eclipse will run one by one. Let it execute and wait till that time.

Till the time its executing the scripts, you should see a grey circle continuously blinking in front of console output. Once it is complete and there are any failures, circle should be in red color. For pass, circle should be blue.

If there are any failures, you should see “[ERROR] There are test failures” in red font. And before that you should see test summary such as “Tests run: 1, Failures: 0, Errors: 0, Skipped: 0”

  • Jenkins Test Result and Test Result Trend:
  1. Click on “DemoTestJobs”→ Click on build number. Click on “Test result”. You should see complete test result summary.

2. Now if you again click on “DemoTestJob” you should see Latest Test Results and last build execution time.

3. Now lets suppose after the failures, developer has fixed some issues and given a new build. You will incorporate the changes in your eclipse project and will build again. Click on build now and second build will be executed (#2)

4. Now suppose you have run your build multiple times, you should see your build number incrementing under “Build History” (Build #1, #2, #3, and so on)

5. After you have executed more than 5–6 builds, you can also see “Test Result Trend” graph. Click on the project “DemoTestJob” and see the trend graph at the right.

How to remove fully Jenkins installation in Ubuntu:

  1. If your jenkins is running as service instead of process you should stop it first using
sudo service jenkins stop

2. After stopping it you can follow the normal flow of removing it using commands respective to your linux flavour

For ubuntu it will

sudo apt-get remove --purge jenkins

3. You should also run the following 2 commands because otherwise the system will look for jenkins updates on apt-get upgrade.

"sudo rm /etc/apt/sources.list.d/jenkins.list" and

"sudo rm /etc/apt/sources.list.d/jenkins.list.save”

4. Lastly remove .jenkins from root

“rm -rf ~/.jenkins”

Sonal Dwivedi

Written by

Quality Test Engineer (Manual+Automation) @Jio, Passionate about selenium

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade