Jenkins tutorial | Jenkins tutorial for beginners | Jenkins

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello welcome to the complete Jenkins course in this introduction lecture we'll see what this course covers and what you will learn from this course in the first section we'll develop a conceptual understanding of continuous integration continuous delivery and continuous deployment and the difference between those concepts then we'll talk about different phases of adopting continuous integration into your organization we'll give a brief introduction to Jenkins and the history of Jenkins next we'll learn how to install Jenkins on your local computer no matter whether you are using Windows Mac or Linux you would be able to follow along then we'll get to know Jenkins master and slave architecture develop our understanding of some of the most important jenkees terminologies such as jobs builds and notes and we'll try out our first Jenkins job which simply prints out hello world in the council in section 2 we're going to create and run a maven project since Jenkins natively understand maven and offers excellent features for maven based projects this project involves and checking out source code from github compiling running unit tests and packaging the application in the end of section 2 will cover other Jenkins build triggers such as trigger build remotely filled after other projects are built and built free erotically in section 3 will be focused on continuous inspection we're going to learn how to produce code quality and code coverage report such as checks tile report for our maven project we would also talk about Jenkins support for other built systems such as Apache end and Gradle in section 4 we're going to extend our existing Jenkins job to an automated continuous delivery pipeline which would deploy our application to a staging and production environment in this section we'll create multistage Jenkins jobs and visualize the complicated build pipeline with Jenkins build pipeline plugging we would also cover how to shorten the build time by running projects in parallel in section five we'll see how to scale our Jenkins workflow with Jenkins master and slave architecture to deploy and configure a multi node Jenkins cluster in the cloud environment in the end we would also look at some advanced tricks such as labeling Jenkins nodes so that we can reserve some specific Jenkins nodes for certain kinds of jobs that's it for this introduction lecture I'll see you later hello everyone in this lecture we're going to talk about how you should take this course and how to get support a lot of slides provide practical information on how to do things the source code for this course is uploaded to github will also keep the repository up to date with new and extra information we have put most of the complicated commands we're using this course to the text lecture right after the video lecture so that you can copy and paste those commands and try out on your own laptop we also have a Facebook group called learning DevOps and LevelUp Facebook group is a fantastic tool that we can use in so many of the communities we're in and we hope it would be a great way for extending this course and adding more value to your learning you can post your questions in the Facebook group and we'll try to get back to you as fast as we can we also periodically share the latest trend in the DevOps world and some practical tricks we found useful you can scan the following barcode or use the link in the next text lecture after this video lecture to find a group in this lecture we're going to talk about what is continuous integration why we need it and different phases of adopting continuous integration Jenkins is a continuous integration and a built tool we need to understand continuous integration before I start playing with Jenkins continuous integration is a development practice that requires developers to integrate code into a shared repository several times a day each check-in is then verified by an automated build allowing teams to detect problems early a continuous integration system usually involves a tool that keeps monitoring your version control system whenever a change to version control system is detected the system would automatically build and test your application if the build where a test is not green the system immediately notifies the developers to fix the issue right away so why do we need continuous integration one of the motivating forces behind CI is to detect problems or bugs as early as possible in the development lifecycle since the entire code base is integrated built and tested constantly the potential bugs and errors are caught earlier in the lifecycle which results in better quality software next let's talk about different stages of adopting continuous integration introducing continuous integration into organization is not something can be achieved in just one step usually it takes you on a path that progresses through several distinct stages let's take a look an approximate picture of each stage Stage one there are no build servers at all for the team the application is built manually on a developer's machine the source code is stored in a central repository but is not enforced the developers need to commit their changes on a regular basis what happens is that before release a developer or a release manager would manually integrate the changes during this stage the code change is made by all developers were brought together and forged into a product this sometimes involves any graded months of conflicting changes which makes it very hard to anticipate the types of issues that would come up also it takes a lot of effort to resolve those issue because the lots of the code might be written months ago does this painful process can cause significant release delays Stage two the team has a built server and automated builds are scheduled on a regular basis typical a nightly basis this built script would compile the application and runs a set of automated tests developers now commit the changes regularly usually at the end of every day if a developers commits conflict with another developers work the build server would alert the team members stage 3 the team is now starting to take continuous integration and automated testing to a further step the beauty server is configured to start a build whenever new code is committed to the central repository the build process usually involves compiling the application and runs a set of automated unit or integration tests the buttes are alerts team members immediately if a build fails broken builds are usually treated as a high priority issue and is fixed quickly Stage four automated code quality and code coverage metrics are now run along with unit tests to continuously evaluate the code quality gradually the CI process gathers useful information about our code base will be able to answer questions such as is the code coverage increasing do we have fewer and fewer built failures this helps teams keep the quality bar of the codebase high we'll be notified if good tests and practices are slipping Stage five confidence has been built up in the automated unit integration and acceptance tests so that automated deployment techniques can be used to push out new changes directly into production next let's talk about the difference between continuous integration continuous delivery and continuous deployment there was a lot of confusion about these buzzwords continuous integration is the practice of merging development work with a main branch constantly so that the code is tested as often as possible to catch issues early continuous delivery is the continual delivery of code to an environment once the code is ready to ship this could be staging or production but the idea is the product is delivered to a user base for review and inspection which can be qh or customers unit tests during continuous integration cannot catch all the bugs in business logic particularly design issues this is why we need a QA or staging environment for testing continuous deployment is the deployment or release of Kult to production as soon as it's ready continuous deployment requires continuous integration and continuous delivery otherwise the called quality won't be guaranteed in the release so how can we implement continuous integration there are different products and tools which can help you implement continuous integration in your organization some tools let you host the CI servers in your own network infrastructure such as Jenkins there are some other hosted CI products such as circle CI which is completely hosted in the cloud in this course we'll be focusing on Jenkins server continuous integration is also a mindset when continuous integration is introduced and in tune an organization it dramatically changes the way how organizations think about the whole development process continuous integration is not only a tool set but also a mindset in order to get the most out of continuous integration a team needs to adopt a CI mentality fixing broken builds should treat it as a high priority issue for all team members the deployment process should be automated with no manual steps involved all team members should focus on contributing to high quality tests each of these requires improvements in the practices and engineering culture of continuous integration across the organization in this lecture we'll give a brief introduction about Jenkins and the history of Jenkins Jenkins is a continuous integration and Bueller it's used to manually periodically or automatically build software development projects these project skills can include complication running automated tests packaging application or even deploy to production Jenkins is an open-source continuous integration tool written in Java Jenkins is used by teams of different sizes for projects with various languages such as Java dotnet PHP Ruby groovy etc so why Jenkins have been so widely used firstly it's very easy to use the UL is simple intuitive and visually appealing and Jenkins as a whole has a relatively low learning curve as we'll see in the next few lectures you can get started with Jenkins in just a few minutes also it has great extensibility it's extremely flexible and easy to adapt to your own purposes you can find thousands of open-source of plugins are available these plugins provide various functionalities such as version control systems code quality metrics built notifiers UI customization etc next let's talk about the history of Jenkins Jenkins was originally developed as the Hudson project Hudson's creation started in the summer of 2004 at Sun Microsystems one of Suns developer called Kooskia Kikuchi started the project as a hobby project under the name of hudson in late 2004 it was first released in February 2005 as Hudson involved over the years it was adopted by more and more teams within sun for their own projects by early 2008 sun recognized the value of hudson and asked Kooskia to work on hudson full-time and to provide professional services and support around hudson by 2010 Hudson had become the leading continuous integration solution with the market share of over 70% in January of 2011 the project name was changed from Hudson to Jenkins and that's it for this lecture I hope you've enjoyed it in this lecture we'll learn how to install Java on our local laptop Jenkins is an java application and requires at least Java 7 to be installed on your local machine in order to run Jenkins and is recommended to install Java 8 first let's verify if Java is installed on your laptop here just launch a command line terminal then type Java - version if you already have Java installed this command would print out which version of Java is currently being used if you don't have Java installed on your laptop or your java version is older than 7 let's move on to install Java on your laptop if you already have the desired Java version installed you can skip to the second half of this lecture to configure Java home environment on your laptop here we Google install Java SC the third entry is the official website to download Oracle Java development kit just click the link on the Java SC development kit downloads page accept the license click the corresponding installer that matches your platform since I'm using Mac I'll download the Mac installer I'm fast forward in the video until the download is complete once the Installer has downloaded just run the Installer and accept all defaults type your password to proceed now the download is complete next we'll configure the Java home environment variable Java home in Barbara ballpoints - the installation path for the Java development kit and it's required by other applications which uses Java the steps to configure Java home environment variable vary depending on what operating system you are using I'll be demoing how to configure Java home environment variable on Mac if you're running Windows or a Linux machine you need to follow the instruction on the next lecture first let's find out where Java is installed on Mac Java is usually installed under slash library slash Java slash Java virtual machines let's enter the directory then let's list what's under the directory as you see I have several different versions of Java installed I'm a laptop let's enter the one we just installed which is jdk 1.8 point o 101 did enter contents home now the current directory is the directory where Java is installed just do PWD and copy the path of current directory then open the DAAD batch underscore profile file which is usually under the home directory this file is read and the commands in it are executed by bash every time you log into the system the best part is that this file is subsequent effect other users on the same system by changing it here let's X bar the environment variable Java home to the path which we have just copied then just save the file now we're done with configuring Java home next time when you're logging in the system the Java home environment variable will be automatically set to our current Java distillation path that's it for this lecture I hope you've enjoyed it in this lecture we'll install Jenkins on our local box just Google installed Jenkins let's scroll down and click the Jenkins installation and setup page then click the Downloads on the top left let's download the LTS release which is a long term support release the current LT release is two point seven point two just Mouse hover the red button with LTS release version it displays a drop-down manual with all different operating systems that Jenkins supports since I'm using Mac I just clicked Mac os10 if you're using other operating systems just click the one matches your operating system now it's downloading the jenkin installer for mac i've fast forwarding the video until the download is complete after the Installer is downloaded let's open it up just click continue to proceed then agree to the License Agreement then type your password to continue after the installation is complete these Staller launches the browser and open up loco host port 808 o which is the default port that Jenkins friends on for the sake of security Jenkins has written the initial login password for admin user to the following file let's copy the file path and displayed the file content in a terminal whoops we don't have permissions to access this file just add sudo to run the command with security privileges see we have retrieved the admin password just copy the password go back to the login session and paste it to the input box and click continue now Jenkins is suggesting us to install some Jenkins plugins we'll talk more about plugins later for now we just click the cross sign on the top right to skip the step finally jenkin is ready click start using Jenkins now we're logged in Jenkins first thing we do here is to change the admin password to something more meaningful so that we don't have to copy and paste a lengthy random string each time we log into Jenkins just click this add me user @ account on the top right then configure in the password section just type the new password click Save we're done with resetting the password so next time you can use admin user ID and the password you just set to log in to Jenkins that's it for this lecture I hope you've enjoyed it in this lecture we're going to take a look at Jenkins master slave architecture and introduce some important Jenkins technologies Jenkins uses a master and slave architecture to manage two distributed builds the masters job is to handle scheduling build jobs dispatching builds to the slaves for the actual job execution monitoring the slaves and recording the build results and presenting the built reports it's worth mentioning that even in a distributed architecture a master instance of Jenkins can also execute build jobs directly a Jenkins slave it's a small Java program that listens for requests from the Jenkins master the job of the slaves is to do as they're told which is mainly executive build jobs dispatched by the master it is possible to configure a job to always run on a particular slave machine or a particular type of slave machine next we'll get familiar with some of the key concepts within Jenkins the first one is job or project Jenkins seems to use these terms interchangeably they all refer to runnable tasks that are controlled or monitored by Jenkins slave or node slaves are computers that are set up to build projects for a master Jenkins run a separate program called slave agent on slaves when slaves are registered to a master a master starts distributing loads to slaves known is used to refer to all machines that are part of Jenkins grid slaves and master next is executor executor is a separate steam of bills to be run on a node in parallel a node can have one or more executor a build as a result of one of the projects a plugging like plugins on any other system it is a piece of software that extends the core functionality of the core Jenkins server that's it for this lecture I hope you've enjoyed it hello in this lecture we'll give a high-level overview of Jenkins web console let's go to Jenkins web interface first just go to localhost port 808 Oh then type admin and the password is set in the last lecture to logon into a janking web interface the main section on the landing page is a job listing section which is supposed to have our job list however since this is a fresh installation of Jenkins therefore no jobs are listed yet on the left hand side there are some menu items viewed queue and boot executors status let's take a look at these menu items a new item the item refers to a job or a project so this menu item helps us to create a new job next is people this menu item manages users within Jenkins build history shows us a history of builds in this Jenkins instance it includes the builds that were executed not only on the master node but also on the slave nodes next is manage Jenkins let's take a quick look into this section and explore some of the items on this management page this configure system item can help us to configure global settings and paths such as the path to maven and Java the configure global security item configures who can view and edit the Jenkins system through this web console the manage plugins item can add remove disable or enable plugins that can extend the functionality of Jenkins we will explore jenkees plugins in greater detail in a separate lecture next is system information and system logs these are useful if he want to troubleshoot some of the Jenkins system issues so that was a high-level overview of manage jenkins page let's get back to the landing page again my views item would display a private view which provides a possibility for every user to have its own filter of Jenkins jobs the last menu item here is the credentials menu item which is responsible for managing all the global credentials in Jenkins the build queue status here shows all the builds that have been triggered next on the build executors section displays the current built executors on this Jenkins instance that's it for this lecture I'll see you later hello and welcome back in this lecture we'll start creating our first Jenkins job we're now at landing page there aren't any jobs created you have a nice little inviting message to create a new job so let's click on create new jobs then we need to give the new job a name basically the project name can be anything you like but it's worth noting that it will be used for the project directory and the build job URL so we should avoid names with spaces here we name it first - Jenkins - job next is to choose the type of project we want to create currently we have only freestyle project Jenkins is really versatile can be used to perform lots of different build jobs such as continuous integration nutley builds perform some repetitive batch tasks etc the Freestyle build jobs are general purpose-built jobs which provides a maximum of flexibility so that you can tailor it to your needs next we're going to start off with the Freestyle project so select an item and then click on the ok button next let's input the project description the project description we're going on the project home page it provides an overview of the build jobs goals and context just type this is our first Jenkins job now we're at the job configuration page as you see the job configuration page has been divided into several sections the first section is some basic information such as the name and description of the project which we have already filled in and some other options about how and where the build jobs should be executed the other options are more technical you can disable ode builds build jobs can consume a lot of disk space especially if you store the build artifacts even without party facts keeping a record of every bill Jobs consumes additional disk space and memory the discard old builds option lets you limit the number of builds you record in the build history you can either tell Jenkins to only keep recent builds or to keep them no more than a specified number of builds you also have the option to disable the build a disabled build will not be executed until you enable it again using this option when you create a new build job it's quite rare but this option is very handy if you want to temporarily suspend a build during maintenance work or major refractory the next section is a source control management section which defines the source of the code which will be built by our job Genki supports CVS and SV and out of box our first Jenkins job won't check out any source code so just leave none as default the next section is the build trigger section we can define multiple triggers for this job if we don't specify the triggers the job can only be triggered manually in our first job will trigger this job manually and next is the build section where we define the actual build steps built steps are the basic building blocks for the Jenkins freestyle build process build steps tell Jenkins exactly how we want our build project we can defy as many steps as we want within a job here we click add built step then we select execute show if you're on a Windows system you probably want to select execute Windows batch command then we just echo hello Jenkins which should print out hello Jenkins message for us the last section is the post build section where we can define some most build processing steps these steps will execute where the build is successful or not usually we use the post build jobs to define our notifications to send out emails to the development team Jenkins can also collect information out of the build such as archiving the artifacts recording Javadoc and test results we won't do any post build actions in this demo so let's live in empty now we're done with configuring our first job we can click on the Save button great after saving the configuration for our first job let's go back to our landing page see the new job appears on our landing page that suits for this lecture I'll see you later hello and welcome back in this lecture we're going to build our first Jenkin job which we created in the previous lecture and inspect the results now we are at the landing page of Jenkins on the right side of the landing page under an alt tab Jenkins lists all jobs that we have created in our Jenkins interface we have only created one job so far let's just click the build now button on the last column of our project entry to fire off our first job execution then we click the job name to enter the main page of the project see that build was scheduled there is a blue ball displayed under our build history this tells us the last no state of our built in Jenkins blue ball indicates success and if we click on the ball it take us to the main page for this build now if we click council output we can see the council output of that job see it prints out hello Jenkins in the council you also have the option to delete the build which we may do later let's go back to the landing page click back to project then back to dashboard on the job list it shows first Jenkins job which is our first job and then which build number that I'm on currently it's build number one if you click on build number one janking will take us to the main page for this build which would just saw the first column is status column as we mentioned before the blue ball indicates the last run was successful the second column is the weather which shows an aggregated trend of all the builds that had happened recently sunshine means that all the recent builds are successful then we have the last failure since we haven't had any failures and /ay is displayed next to the last failure column we have the last duration column which displays how long the last built took in our case it is 93 milliseconds and then in the final column we have a build now but which will allow us to trigger enemy to build that's it for this lecture I hope you've enjoyed it in the previous lecture we have seen how to create and trigger a simple Jenkins build job but the Jenkins job doesn't do much besides printing out the holo janki's message in this and the following few lectures we'll set up a more practical maven based build this Jenkins job would check out the source from github compile the code run the test and package the application the project we're going to build is a very simple maven project since it's a git project and it's hosted on github we need to install git on our local box and install github plugging on Jenkins let's start by installing get if you already have git installed you can skip this step to verify if get installed on your local box just open up a command line terminal and type get - - version if kit is installed you would see the kid version printed out on the screen now let's go go download kit the first entry is the official get installation page the installation steps vary depending which operating system you're running on since I'm using Mac OS I just click Mac os10 to download the get installer for Mac OS you should select the one matches your operating system now the get installer has been downloaded I'm fast forward in the video until the download is complete now these dollar is downloaded let's open up the Installer just click continue to go with the default option type your credentials to proceed now the installation is complete you can verify kit is successfully installed by running get - - version next let's move on to install github plugin for Jenkins this plug-in any great Jenkins with github projects you can learn more about this github plugin by visiting the plugin page Here I am at the Jenkins landing page just click manage Jenkins then go to manage plugins click on the available tab the plugins that we're interested in is to github plugins let's go to the filter search and type in github see Jenkins locate the github plugin for us then click the checkbox next to it there are two buttons to install the plugin install without restart and download now and installed after restart since Jenkins 1.44 2 we're able to install new plugins without restarting Jenkins when installing new Jenkins we usually choose installed without restart if you are upgrading a plugging we need to choose download now and install after it start here we click on install without restart now Jenkins starts the installation process if this is fresh install for you you might have noticed that Jenkins is also installing some other plugins for us this is because Jenkins automatically found any dependency plugins such as the github API plugin and the gate plugging and included those as well when the download is complete which you see the success ball here now we go back to the landing page let's click manage Jenkins again then click on manage plugins this time we click the installed tab see we have our github plug-in installed and the version is 1.2 1.1 that's it for this lecture I hope you've enjoyed it in this lecture we'll continue our preparation work to set up our first maven based build job we'll be installing maven in this lecture the project we're going to build it's managed by maven build framework maven addresses two aspects of building software first it describes how the software is built and secondly it describes its dependencies there are many java build tools available such as maven and and grado Grado is getting more and more popularity but maven is still the most widely used one at this moment jenkins provide excellent support for maven and has a good understanding of maven project structure dependencies let's go go download maven the first entry is the official apache maven website now we're at the download page scroll down to the available download options let's pick the binary zip go to the column for the link and click on the link now it's downloading the entire distribution for Apache maven I'm fast-forwarding the video until the download is complete once the da zip file has complete downloading it should appear in the download folder I prefer to place all my development tools in a common place which is the document folder but this can be any location on your local box next let's extract the DAAD zip file a Mac OS I just double-click the dot zip file in Windows you can right-click on it and then choose extract all from the pop-up menu once the extraction is complete a new folder would appear under the same directory the folders should be named after Apache maven plus the version number next we need to add the bin directory of this new folder to the path environment variable so that our operating system knows where to find our maven executable this step varies depending which operating system you're running on if you're using Mac or Linux you should be able to follow along if you're using Windows just go back to the Maven download page and click install then scroll down just follow the windows tips section to update the path environment variable now let's see how we can do this on a Mac or Linux machine first let's get the full path of the maven executive o path just enter documented directory then the extracted folder then Bing directory let's do PWD to print out the current directory then copy and paste the full path let's open up the DUT bash underscore profile bash file let's add one more command to add the maven executive a path to the path environment variable then exit the file now we're source the bash file to load the environment variables in the current session once everything is set up correctly if we type MV and - V here it would print out the maven version for us that's it for this lecture I hope you've enjoyed it hello and welcome back in this lecture we're going to set up our Jenkins configuration in order to run our first two maven based a project to set up Jenkins configuration go to manage Jenkins then click global to a configuration that loads the Jenkins configuration for us as you see there are a couple things we need to setup we need to add a JDK a kid and maven installation so that Jenkins knows where to locate those tools during the build process let's start with the java jdk so under jdk j takeda installations click add jdk we need to fill in the name which can be anything we want to name this installation of jdk here I just put loco jdk by default jenkins will have install automatically checked but since we've already installed the JDK on our local box so let's uncheck install automatically and filling the Java home field with a path where Java is installed on our local box if you don't remember the path go back to the Java installation lecture to find it out next let's configure our get installation we just follow this same process click on add get then get let's give this get installation a name I'm going to call it local gate since we're able to just type kit in the command to invoke it executive all here we don't need to add a full path to get just type in git lastly let's move on to configure our maven installation click on add maven then name the maven installation local maven as what we did for JDK just uncheck install automatically and like Java home maven home is Defoe path to where we have Mabon installed if you don't remember the full path just go check the previous bavin installation lecture it's noted this Mayman home path doesn't include the bin directory in the end now that we've updated our Jenkins config raishin let's click on save you might have noticed that we have two buttons here save and apply what is the difference the apply button will save the changes we have made so far but then remain on the current configuration page so that we can continue making changes the Save button will save our changes but then take us to the previous page since I don't have any further changes to make save is the right choice for us that's it for this lecture I hope you've enjoyed it hello and welcome back finally we've got all our preparation work ready it's time to create our first maven based job let's take a look at the project we're building the project we're going to build is hosted on github this is a fairly simple project which I have adopted from another project for the purpose of this course this project is basically a web application which displays hello world on the browser like this let's quickly go through the structure of this maven project I have a copy of this project on my local box this project has two modules web app module and the server module the web app module has a weapon dot XML deployment descriptor file which contains the minimum information about how to deploy this web application the index dot JSP file basically describes the HTML page we have seen in the browser which is hello world the server module contains a very simple Java class and a corresponding test class which are not even related to the business logic of this web app we'll take a closer look at them later in this course when we demonstrate the usage of some static analysis tools in maven you probably have already noticed that we have three pom dot XML files in our project maven uses pod dot XML files to describe the software project been built including the dependencies on other external modules the directory structures and the required plugins etc in the pom dot XML file it also specifies predefined targets for performing certain tasks such as compilation and packaging now let's start creating the Jenkins job Here I am at Jenkins landing page click on new item type in a name let's call it maven project here we just go with a freestyle project once you've selected that click on ok great let's move on to configure our jenkees project in the description field let's put this is our first maven project next let's move on to the source code management section well check out the source code from github so here we check it then we'll need to supply the repository URL I have the Maven project open on another tab let's click the green clone or download button then click the small copy icon to copy the repository URL to clipboard then go back to Jenkins just pasting that value to the repository URL input box since this is a public repository we don't need to provide any credentials to check out the source code for the branch specifier since this project only has a master branch just live it as master will trigger this job manually in this lecture so we won't check any of the options in the build triggers tab the next thing we need to tell Jenkins is what to do with a source code this is done by defining built steps for this step will create a maven target and use our configured instance of maven which is called local maven then maven goals goes are basically the phases of maven build in case you don't know what is maven build lifecycle let's take a quick look at different phases in may demand build lifecycle the default lifecycle comprises of the following phases validate validate the project is correct and all necessary information is available compile compile the source code of the project test test the compiled source code using a suitable unit testing framework package take the compiled code and package it in its distributable format such as a jar verify run any checks on results of integration tests to ensure quality criteria are met install install the package into the local repository for use as a dependency in other projects locally deploying copy the final package to the remote repository for sharing with other developers and projects these lifecycle phrases are executed sequentially to complete the default lifecycle in our case we want to specify the maven package command this command would execute each default lifecycle phase in order including mela date compile tests before executing package we only need to call the last built phase to be executed let's go back to the gemenese configuration page in the maven ghost section which put clean in package the clean command will ensure we have a clean environment before executing any further maven build steps at this point we're done with configuring this maven job just click on save in the next lecture will trigger this job and check the outputs that's it for this lecture I hope you've enjoyed it in this lecture we're going to actually trigger the Maven job we created the last lecture and take a close look at the build process now we have opened the maven job on Jenkins let's click build now to trigger the build see the build is scheduled there is a blinking green ball in progress bar displayed under the build history section which indicates the Bilt is in progress now the gray ball turns blue and stops blinking which means the build has completed successfully we click the number one besides the blue bar it takes us to the main page of this build then click council output to see the council output of this job let me walk you through the logs printed on the console to understand what happens during a build as you see Jenkins builds the project in a workspace under a shared directory on this logo box first it checks out the source code from github then it's going to execute the maven clean and package commands maven figures out the right order of fielding all the modules of the maven project the first one is the root directory then the server module and the web app module for the root directory that only does the clean command to remove any previous artifacts generated in the target directory then it moves to the server module Jenkins is executing the sequential maven build commands such as compile and test before packaging after executing all the unit tests it prints out unit test reports lastly it packages the server module and produces the server yard file under the target directory in the server module after it's done with the server module Jenkins moves to build the web app module the build steps for the web app module are pretty similar to the server module clean compile and test in the end it packages the web app module and produces the web at not war file which can be further deployed to a servlet container like Tomcat before he finished this lecture let me show you how we can navigate through the workspace on Jenkins web portal here we click the maven project on the navigation bar to go back to the main page of his job then click workspace now it displays the directory structure of this workspace which Jenkins uses to build the project you can just click any directories to explore the workspace that's it for this lecture I hope you enjoyed it in the previous lecture we have seen how to trigger our build job manually but the whole point of continuous integration is that whenever a commit is pushed to the central repository the system would automatically build and test your application the easiest way to achieve this is to let Jenkins pull the source code on github periodically if Jenkins detects a change in the source code based on the polling it would then trigger a build let's see this in action Here I am at the Jenkins landing page just click the maven project which is created then click configure scroll down to the build trigger section and check poll SCM option then in the schedule field we'll need to filling how often we want Jenkins to pull our source code this field follows the syntax of cron cron is very important concept working with job scheduling services such as Jenkins let me quickly walk you through some of the basic syntax of cron in cron each line consists of five fields separated by tap or whitespace starting from left to right those fields are minute our day of month month and day of week to specify motiva values for one field we have the following options the star sign specifies all valid values M dash n specifies a range of values a comma B comma Z enumerates multiple values for example oo star star star means every day at midnight o 2-4 star star star means 2:00 a.m. 3:00 a.m. and 4:00 a.m. every day in order to detect changes immediately we would like to pull the source code as frequently as possible so here we just put 5 star here which tells Jenkins to pull SCM every minute then click Save to save the configurations we end up with an extra item in our menu section get pulling log let's check it out it says polling has not started yet let's wait for about a minute and click get polling lock again see it shows us that Jenkins just checked out for changes and in the end no changes were found Jenkins is doing this check every minute now in order to trigger a build on Jenkins we need to make some changes to the repo on github which then could be detected by Jenkins unfortunately you won't have permissions to make changes to make it hub repple directly in order for you to follow along this course you would need to fork my repple on github which will create a copy of the repository under your user ID and allow you to freely make changes without affecting the original repository let me show you how to fork the repository just go to my github repository HTTP s github.com jelly tutorial maven - project now we have opened a maven project repository let's click the fork button to fork the repository see we have got our own version of maven project repository now we can tell Jenkins to check out source code from the forked repo instead of the original one and click the clone or a download button which displays the git clone URL for you to download the ripple here you need to select using HTTPS instead of using SSH so that Jenkins will need SSH credentials to check out the rip hole next click the clipboard icon to copy the URL to your clipboard and go back to Jenkins and click the maven project we just created then click configure move to the source code management section and replace the original GUID URL with a new one then click Save to save the configuration before we push changes to the github repo one last thing you need to do is to setup the SSH key for your github account so that we can push changes from your local box to the central github repository more easily SSH keys are a way to identify trusted computers without involving passwords you can generate a SSH key pair and save the private SSH key in your local box and add the public key to our github account now you can directly push your changes to github repository without typing password first you should check if you already have the SSH key available in your local box the public key file usually sits under the hidden SSH directory in your home directory and it usually ends up with dot pub extension I don't have an SSH key pair in this computer so I will go ahead and create one if you already have one feel free to skip the step now let's follow the instruction on the github website to create an SSH key pair just copy that SSH kitchen command to our terminal to create as SSH key here with sick with example email address just keep hitting Enter to go with the default options the private key and public key have been generated what we'll do next is to start SSH agent in the background and add the SSH key to the agent now let's copy our SSH public key to the clipboard so that we can add it to the github finally we go back to the github profile and click the settings SSH key and CPG Keys click new SSH key and give the public key a title and paste the public key here and click Add there you go the public key has been added to the github finally let's check out the repo and make some changes go to the forked maven project repository under your github account make sure you go to the forked repository under your github ID now the original one otherwise you wouldn't have permissions to push changes to the repository and click clone word download button here you need to select using SSH instead of using HTTP next just click the clipboard icon to copy the URL to your clipboard then we go back to the terminal issue git clone command and paste the URL and hit enter now git is downloading the repository to your local box the repository has been downloaded let's enter the repo and do an empty commit just put something as the commit message then exit now we can do git push to push the latest commit to the remote repo this should trigger a build on Jenkins let's hop back over to Jenkins refresh the guid polling log see it says Jenkins has detected the changes and we can see a build has been scheduled after the build is complete click this bill as you see this build is successful and it says the build is started by a SCM change in this lecture we have demo on how to configure Jenkins to pull our github repo periodically so that a build will be triggered immediately whenever a commit is merged to the central repo that's it for this lecture I hope you've enjoyed it
Info
Channel: Level Up
Views: 36,669
Rating: 4.9753084 out of 5
Keywords: Jenkins tutorial, Jenkins
Id: -wZeZSMlvhM
Channel Id: undefined
Length: 59min 18sec (3558 seconds)
Published: Fri Jul 06 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.