Jenkins Cheat Sheet

Jenkins Cheat Sheet

Last updated on 08th Oct 2020, Blog, Tutorials

About author

Jagadesh ((Team Lead DevOps Engineer ) )

Highly Expertise in Respective Industry Domain with 7+ Years of Experience Also, He is a Technical Blog Writer for Past 4 Years to Renders A Kind Of Informative Knowledge for JOB Seeker

(5.0) | 12547 Ratings 1862

DevOps enthusiasts are generally looking to explore different tools that are frequently used in the workplace. If you are one of them then you have landed on the right page. DevOps professionals are generally paid higher and high in-demand worldwide. Keeping all these things in mind, let me introduce you to one of the most popular DevOps tools, Jenkins.

Subscribe For Free Demo

Error: Contact form not found.

What is Jenkins?

Jenkins is an automation tool written in Java programming language and suitable Continuous Integration tasks. It is used for continuous building of projects and you can quickly integrate the changes when needed. Also, Jenkins helps in the rapid deployment of a project by utilizing a wide number of deployment technologies. The acceleration in the development phase is achieved by automating tasks. Like a team lead, Jenkins will continuously check and evaluate the code for identifying unexpected errors early in the development phase.

Jenkins is an automation tool written in Java programming language and suitable Continuous Integration tasks. It is used for continuous building of projects and you can quickly integrate the changes when needed. Also, Jenkins helps in the rapid deployment of a project by utilizing a wide number of deployment technologies. The acceleration in the development phase is achieved by automating tasks. Like a team lead, Jenkins will continuously check and evaluate the code for identifying unexpected errors early in the development phase.

Jenkins-Cycle

Jenkins Installation

  1. 1. First of all, you should install Java. $ sudo apt update $ sudo apt install openjdk-8-jdk
  2. 2. In the second step, the Jenkins repository should be added. $ wget -q -o -https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add –
  3. 3. Now, add the Jenkins Repository to the system $sudo sh -c ‘echo deb http://pkg.jenkins.io/debian-stable_binary/>/etc/apt/sources.list.d/jenkins.list’
  4. 4. In the 4th step, you should install Jenkins $ sudo apt update $ sudo apt install Jenkins
  5. 5. Once you have setup the installation, it is the right time to verify the Jenkins Installation. $systemctl status Jenkins

Now, Jenkins is ready to run on your system, you can access it through the following link. http://localhost:8080

What is Continuous Integration (CI)?

CI is a software development practice that helps developers to commit changes frequently to the source code in a shared repository. Every commit is pulled continuously and built. Jenkins is a CI tool that continuously builds, pulls, and tests the source code using plugins. in this blog, we will discuss the Jenkins cheat sheet for beginners that is necessary to learn before you start with the software development process using DevOps.

Management :

Configure system:

  • Can be used to manage paths to various tools to use in builds.
  • Jenkins dynamically adds the config fields after the plugins are installed.

Manage Plugins:

  • Plugins can be removed, updated and installed by manage plugin screen.

System info:

  • List all the current java properties and system environment variables.
  • System log- view Jenkins log in real time.
  • Script console- lets you run groovy scripts on the server.
  • Manage nodes- configure the number of builds you want.
  • Shutdown- click prepare to shutdown link to prevent any new builds from being started. After all current builds are finished, Jenkins will shut down cleanly.

Unit Testing :

Testing unit in Jenkins:

Step 1 : Go to the dashboard and choose an existing project and click configure

Step 2 : browse to add a build step and invoke Ant

Step 3: Click on advanced

Step 4 : in the build file section enter the location of build.xml

Step 5: add post build option and click Publish Junit test result report

Step 6 : ensure the report is in the folder of the project workspace The “*.xml” basically tells Jenkins to pick up the result xml files which are produced by the running of the Junit test cases. Click Save after done.

Step 7 : Click on build and check logs to see if successful or not with applications.

Automated Testing :

Step 1: go to plugins and choose selenium plugins and click to install.

Step 2: go to configure system and select on selenium jar and save

Step 3: Go to dashboard and select the config option for the project at hand

Step 4: Click on add build step and choose SeleniumHQ htmlSuite Run”

Step 5: Add the required details and click on save, execute and build. The test is executed, and a report is built.

Automated Deployment :

  1. 1. Head to the manage plugins and install the respective plugins
  2. 2. It takes the war ear file and deploys that to the running remote application build
  3. 3. Go-to build and configure and click on ‘deploy to war/ear to container’
  4. 4. In the war container section save details about the destination server and click save.

Backup Plugin :

  • To tweak backup settings via setup
  • To backup Jenkins config
  • To restore config from a previous backup.
  • Alternatively you can use SCM( sync config plugin) or ThinBackup for global and job configurations.

Notifications :

  1. 1. Jenkins comes with a feature to add email notifications to the build project
  2. 2. Go-to Manage Jenkins → Configure System. In the email notification space enter the require STMP server and use email suffixes.
  3. 3. Configure the recipients so that they would receive notification about broken or unstable builds
  4. 4. Notification plugins such as Tikal Knowledge allows job status notification for JSON and XML formats.
  5. 5. Options :
  6. 6. Format – either Json or XML types
  7. 7. Protocol- TCP, UDP or HTTP
  8. 8. Event – job event that triggers the notification
  9. 9. URL- destination to send notifications to.
  10. 10. Timeout – default timeout 30ms

Manage Plugins :

  • To uninstall plugins , go-to manage plugins and click on the installed tab and click on uninstall for the plugin
  • In Case of need to install an older version of the plugin, download from the site and click on Upload option to do it manually.

Code Analysis :

They provide utilities for static code analysis. Some tools are CheckStyle, FindBugs, PMD etc. Provides details like :

  1. 1. Total warning in a job
  2. 2. Showing of new and fixed warning of a build
  3. 3. Trend reports showing warnings per build
  4. 4. Warnings per module, package or category
  5. 5. Detailed reports of found warnings.

Security :

  • Ability to have secure config for different users in place.
  • Click on manage Jenkins and Configure global security
  • Set parameters in the enable security section
  • Add the users and go-to ‘manage users’ for permissions
  • To set authorizations, go-to configure global security, and click on matrix based security

Server Maintenance :

Commands in Jenkins: (URLs)

  • http://localhost:8080/jenkins/exit − shutdown Jenkins
  • http://localhost:8080/jenkins/restart − restart Jenkins
  • http://localhost:8080/jenkins/reload − to reload

To backup Jenkins Home:

  • 1. Go to configure system in manage Jenkins
  • 2. Select a partition that has to most free space.
  • 3. Perform automated clean-up options to avoid this

Build Pipeline :

  • 1. First go-to manage plugin and install build pipeline plugin.
  • 2. To see a build pipeline click the (+) on the dashboard
  • 3. Enter any name and click on the view. Choose build pipeline view.
  • 4. Accept the default settings and add the name of the project.
  • 5. A view of entire pipeline with statuses will be visible.

Remote Testing :

Selenium tests can be run on remote slave machines via master slave and selenium suite plugin installation

  • Step 1: go-to master Jenkins server and manage nodes
  • Step 2: Click on configure for the slave machine
  • Step 3 : put the launch method as ‘Launch slave agents via Java Web Start’
  • Step 4: open a browser instance of the master Jenkin on the slave machine, then manage nodes and select the DXBMEM30
  • Step 5 : Scroll down and select the launch option and hit run
  • Step 6: Configure tests to run on the slave

Basic Workflow :

  •  Checkout from SCM (like git) 
  •  Branch and make local changes 
  •  Add or change tests as necessary 
  •  Trigger automated build locally 
  •  If successful, consider committing 
  •  Update with latest from mainline 
  •  Push changes, build and test on integration machine

Best Practices :

  1. 1. Maintain a single source repository 
  2. 2. Have a common mainline Branch (usually master) 
  3. 3. Automate the Build 
  4. 4. Minimize potential for user error, automate everything possible 
  5. 5. Make the Build Self-testing – self-testing code 
  6. 6. Everyone commits Frequently (at least daily preferably) 
  7. 7. Communication is key! 
  8. 8. Frequent merges will help avoid conflict errors. 
  9. 9. The working branch should be updated as frequently as possible to help avoid very large diffs while merging. 
  10. 10. Build every commit 
  11. 11. Prioritize fixing broken builds 
  12. 12. Keep your builds fast!! 
  13. 13. Testing environment should be as close to prod as possible 
  14. 14. Make it easy for anyone to get the latest 
  15. 15. Keep it open, everyone should see what’s happening 
  16. 16. Automate the deployment

What is Continuous Delivery?

A software development discipline where software is built so that it can be released to production at any time.

Difference Between Continuous Integration and Continuous Delivery :

  • “Continuous Delivery” is the ability to release at any time. 
  • “Continuous Integration” is just the practice of integrating code continuously.

Continuous Delivery Versus Continuous Deployment :

  • “Continuous Delivery” means the code CAN be released at any time. 
  • “Continuous Deployment” means that code IS released continuously as part of an automated pipeline.

Jenkins User management :

Jenkins uses Jenkins own user database as backend security realm.

can change it to LDAP through Jenkins -> Manage Jenkins -> Configure global security

Jenkins slave/Agent node :

Slave nodes are used to offload build jobs from master.

Jenkins folder structure :

Jenkins installation creates a Jenkins user id on the system but its not for login purpose, 

All the Jenkins service processes on master server will be owned by Jenkins (default) user

if you want to su to jenkins:

  • sudo su (become root)
  • su jenkins -s /bin/bash

Directories – /var/lib/jenkins :

xml files              – config files

secret.key           – is used to build slave/agent nodes

secrets                – used to secure the jenkins

usercontent       – its a simple html documentation on jobs. Create html (job.html) files with notes and browse from Jenkins loginpage /usercontent/job.html

Workspace         – work space for the projects/jobs

Plugins :

plugins can be managed in 3 ways,

  1. 1. Web UI 
  2. 2. Loading HPI files 
  3. 3. CLI
Jenkins Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

Installing plugins through webUI

log into the Jenkins -> Manage jenkins -> manage plugins

updated plugins will be effective on next boot, To manually restart the Jenkins through HPI files :

1. Download the hpi file from the plugin page.

    Jenkins -> manage Jenkins -> mange plugins -> click on plugin -> archives.

2. Upload the file to the jenkins

    Jenkins -> manage Jenkins -> mange plugins -> Advanced -> Upload Plugin (scroll down)

Workspace environmental variables :

These are generic Jenkins variables

  • $BUILD_NUMBER
  • $JOB_NAME
  • $NODE_NAME
  • $EXECUTOR_NUMBER
  • $WORKSPACE

Jenkin projects :

Parameterize the project :

Way to pass arguments to the project/job while running.

Types of parameters :

  1. 1. Boolean
  2. 2. String
  3. 3. Multiline string
  4. 4. Password
  5. 5. Choices

Conclusion

Jenkins Cheat Sheet for beginners is a must go through the blog for people who want to learn Jenkins or want to get into DevOps space. It is not easy learning all features and commands theoretically but you have to practice them thoroughly.

Are you looking training with Right Jobs?

Contact Us

Popular Courses