Complete Jenkins Tutorial | Learn Jenkins From Scratch In 3 Hours 🎯| LambdaTest
Aug 16, 2023
Complete Jenkins Tutorial | Learn Jenkins From Scratch In 3 Hours 🎯| LambdaTest
This LambdaTest Jenkins Tutorial will help you learn the fundamentals of Jenkins and everything you need to know to get started with Jenkins. Start FREE Testing: https://accounts.lambdatest.com/regis … Continuous Testing With Jenkins Pipeline On Selenium Grid Cloud: - https://bit.ly/3Ax5Mij This Jenkins Tutorial for beginners and professionals will help you learn how to use Jenkins, one of the most popular CI/CD tools used in DevOps. In this course, Moss(@tech_with_moss), a DevOps engineer, helps you understand how Continuous Integration and Continuous Delivery happens with Jenkins. This video course covers the basics of Jenkins, how Jenkins works, Jenkins architecture, Jenkins and GitHub integration, and Jenkins installation \u0026 configuration. During this course, you will also learn a step-wise approach for creating your first Jenkins Pipeline, integrating Maven and Jenkins with Selenium, and performing cross browser testing with Jenkins Plugin. By the end of this video, you will know some of the Jenkins best practices that will help you automate the software development pipeline and get better results with this DevOps tool. You will learn: 🔸 What is Jenkins? 🔸 What is Jenkins and why do we use it? 🔸 What are the features of Jenkins? 🔸 How does Jenkins integrate with GitHub? 🔸 What Jenkins is used for? 🔸 How Jenkins works in real-time? Vɪᴅᴇᴏ Cʜᴀᴘᴛᴇʀꜱ 0:00:00 Introduction to Jenkins full course tutorial 0:06:10 Understanding what is Jenkins 0:25:18 Jenkins installation and configuration 0:32:00 How to integrate Jenkins and GitHub 0:58:17 How to create Jenkins Job for Maven project 1:14:22 Adding Jenkins Controller and agent node for Windows 1:26:11 Adding Jenkins Controller and Jenkins agent node in Azure 1:44:09 Understanding Jenkins Pipeline 2:12:53 Cross Browser Testing With LambdaTest Jenkins Plugin 2:52:04 Conclusion of Session Complete Tutorial Series What is Jenkins, and Why is it used? | Part I: https://bit.ly/3fzh1il How to Install and Configure Jenkins? | Part II: https://bit.ly/2VZhNhl How To Install Maven Plugin | Part III: https://bit.ly/38CcOqh Jenkins GitHub Integration | Part IV: https://bit.ly/3skqHSJ Creating Jenkins Job For Maven Project | Part V: https://bit.ly/3g6mflN How To Add Jenkins Controller \u0026 Agent Node for Windows | Part VI: https://bit.ly/3yPowZZ Add a Jenkins controller and Jenkins agent node in azure | Part VII: https://bit.ly/37IOx14 Jenkins Pipeline Tutorial | Part VIII: https://bit.ly/3iUVP8B Cross-Browser Testing With LambdaTest Jenkins Plugin | Part IX: https://bit.ly/3jUH4ln Blogs: What is Jenkins used for?: https://bit.ly/3tJ2Bkz How To Set Jenkins Pipeline Environment Variables?: https://bit.ly/2VFRM6K Best Jenkins Pipeline Tutorial For Beginners [Examples]: https://bit.ly/3fTihwW How To Set Up Continuous Integration With Git and Jenkins?: https://bit.ly/3xBuk7N Are You Following These Jenkins Best Practices?: https://bit.ly/3kvqHNE Learning Hub and Support Documents: Jenkins Tutorial: https://bit.ly/3vaaPT2 Jenkins Plugin for Integration With LambdaTest: https://bit.ly/3CJqNHL Integrating Your Jenkins Pipeline With LambdaTest: https://bit.ly/3hZN6Rm Sign Up for LambdaTest! It’s FREE! Conduct live interactive cross-browser compatibility testing of websites and web apps on latest mobile and desktop browsers: https://accounts.lambdatest.com/regis … Register Now to Avail Bonanza Offerings + Test website on 2000+ mobile and desktop browser environments over LambdaTest cloud + Online scalable Selenium Grid to perform Manual testing as well as Automation testing + 100 minutes of free automated testing For questions: [email protected] YOU NEED TO KNOW 🎬 Most Recent Videos: https://bit.ly/3kUUeAQ 🎓 Learn More At LambdaTest: https://bit.ly/3fr6l4Z 🎥 LambdaTest Customers: https://bit.ly/2TB7pvD 🚀 Webinars: https://bit.ly/37i41co 🛠️ Product Updates: https://bit.ly/3717NGO 💬 LambdaTest Certifications: https://bit.ly/3x4EtcY 📢 FREE For Limited Time Only 🕑, Enroll Now! SOCIAL 📝 BLOG: https://bit.ly/3yGVsUc 👥 COMMUNITY: https://bit.ly/3Aiz5oO 🔴 NEWSLETTER: https://bit.ly/3juhxzc 🖼️ GITHUB: https://bit.ly/3jowfYs 🛠️ YOUTUBE: https://bit.ly/3rH2Yfh 🌎 LINKEDIN: https://bit.ly/3xA6F84 👥 FACEBOOK: https://bit.ly/37mbQOa 🐦TWITTER: https://bit.ly/3Cn0g3A 📸 PINTEREST: https://bit.ly/2VCXI05 #testautomation #crossbrowsertesting #tutorial #testing #Selenium #software #webdeveleopment #jenkins #devops #developers #softwaretesting #jenkinstutorial #automationtesting Disclaimer: This video features materials protected by the Fair Use guidelines of Section 107 of the Copyright Act. All rights reserved to © 2021 LambdaTest. Any illegal reproduction of this content will result in immediate legal action.
Content
5.44 -> hey what's up everybody and welcome
to this tutorial series on jenkins
10.16 -> my name is moss and i'm an experienced devops
engineer with six plus years of experience in the
14.72 -> devops industry now that you know who i am let's
go ahead and take a look at the roadmap of topics
19.68 -> that we're going to cover in this series we'll
start off with the basics and then progressively
24 -> get into more advanced topics related to jenkins
and in our first topic we're going to answer
28.96 -> the question what is jenkins after we have a high
level understanding of jenkins we'll then install
34.4 -> and configure jenkins on our local machine
once we've done that we'll then install and
38.96 -> configure the maven plugin and after we install
the maven plugin we'll then learn how to integrate
43.84 -> jenkins and github i'll then show you how to
schedule jenkins builds using build triggers
50.8 -> once you learn how to schedule builds i'll then
walk you through the creation of a jenkins job
55.12 -> for a maven project i'll then walk you through
the configuration of a jenkins controller and
59.92 -> jenkins agent nodes to facilitate distributed
builds this will lead us to an introduction
64.64 -> of jenkins pipelines and we'll create our
very own pipeline in our jenkins instance
70.32 -> and finally we'll add automated cross browser
testing into our jenkins pipeline using lambda
75.92 -> test now that you know what we're going to cover
in this series let's get started with the first
80.08 -> topic what is jenkins jenkins is an open source
automation server and we use jenkins to automate
89.44 -> certain steps in the software development process
jenkins helps software teams facilitate continuous
95.2 -> integration and continuous deployment or delivery
in addition jenkins is a highly extensible tool
101.52 -> there are hundreds of plugins for jenkins and
these plugins add functionality to jenkins
106.48 -> or they enable jenkins to integrate with other
tools of the software development process
113.04 -> but why do we need jenkins what problem is jenkins
solving in the software development lifecycle
119.04 -> to understand this let's take a look at
a couple of key objectives for developers
123.2 -> the first objective is that developers who are
working in parallel want to make sure that the
128.24 -> features that they're developing integrate into
the latest version of the code base without errors
133.92 -> without jenkins manual integration
of changes happens infrequently
137.76 -> and because manual integration doesn't happen
frequently there's often a large backlog of
142.48 -> changes pending to be merged and this causes the
manual integration process to be time consuming
147.6 -> and we often refer to it as integration hell the
second objective is that developers also want to
152.72 -> make sure that their changes are built and tested
in a standardized environment when a developer is
158.16 -> testing a new feature locally on their machine
their machine configuration might not match the
163.44 -> same configuration of another developer's machine
for instance the developers machines might not
168.48 -> have the same version of the software framework
that they're using to develop their product
172.8 -> and because of this the new feature might work
on one developer's machine but not a different
177.2 -> machine jenkins provides software teams a
stance might not have the same environment
182.24 -> allowing them to avoid this issue now that we know
why we need jenkins let's understand where jenkins
187.68 -> fits into the software development process the
software development life cycle begins with the
192.88 -> requirements definition or planning followed by
the design of the product we then implement the
198 -> product based on the design and once we have an
implementation we then test that implementation
203.2 -> to ensure that it meets the requirements that were
first defined at the beginning of the life cycle
208.16 -> once the product is successfully tested we deploy
it to the customer and perform maintenance or
213.28 -> operations on it jenkins fits into the testing
and deployment steps of the software development
219.28 -> lifecycle and more specifically jenkins helps us
automate the testing and deployment of our product
225.36 -> now that we know where jenkins fits into the
software development process let's take a look
230.16 -> at the architecture of the software development
workflow with jenkins this sequence diagram
236 -> outlines the software development workflow and
it primarily focuses on the role of jenkins in
241.28 -> the software development workflow to begin the
sequence the developer writes code and when they
246.48 -> feel like their code is ready to be reviewed and
tested they then check that code into the source
251.84 -> code repository and this might be a tool like
gitlab or github or bitbucket when the developer
257.68 -> checks in their code to the repository this should
trigger a build in jenkins in this diagram i show
264.16 -> the communication going from the source code
repository to jenkins but this isn't always the
269.76 -> case sometimes jenkins is configured to pull the
source code repository for new changes and anytime
275.84 -> it detects new changes in a particular repository
that will also trigger a build but it's important
281.36 -> to note that it's always best if possible to push
new data to jenkins rather than having jenkins
288.4 -> consistently pull the source code repository
because that might put an unnecessary load on
294 -> the source code repository system once a build
is triggered in jenkins jenkins will then pull
299.36 -> the developer's code changes down to its local
workspace where it will build and test the code
305.44 -> automatically using the latest version of the
code base if the automated build and test steps
310.72 -> complete successfully jenkins will automatically
deploy those changes to the production environment
316.64 -> if the build and test steps fail the automated
deployment will not happen regardless of whether
322 -> the build passes or fails jenkins will still
publish results to the source code repository
327.2 -> it's important to note that jenkins itself is
not performing the build tests and deployment
332.24 -> operations it's simply facilitating the automation
of these steps for instance in the testing step
339.04 -> jenkins may trigger j unit test cases to run
automatically and although jenkins may not deploy
344.72 -> changes directly to the production environment
itself it may utilize a tool like chef or ansible
351.52 -> in order to update the configuration
of the production servers to use the
355.28 -> latest version of the software now that
we have a better understanding of jenkins
359.6 -> architecture we can begin with our next
topic install and configuration of jenkins
370.56 -> hey what's up everybody my name is moss and
welcome back to our tutorial series on jenkins
375.52 -> in this video we're going to be covering how to
install and configure jenkins there are multiple
380.72 -> installation methods for installing jenkins you
can run jenkins from a web application resource
385.84 -> file also known as a war file you can also run
jenkins as a docker container from a docker image
391.92 -> you can install jenkins on windows using a windows
executable file you can also install it on mac
397.04 -> os and finally you can install it on many linux
distributions such as red hat or ubuntu in this
404 -> video we're going to be running jenkins from a
war file and the reason that we're going to be
408 -> running jenkins from a war file is because the war
file is platform and operating system independent
414.08 -> whether you're following this tutorial
from a mac or a windows or a linux machine
418.72 -> you'll be able to run jenkins from a war file
using the same steps that i'll be taking the only
424.24 -> requirement is that you have a supported version
of the java runtime environment installed on your
429.92 -> machine jenkins supports java versions 8 and
11. java versions 9 10 and 12 are not supported
437.92 -> now that we've covered the necessary details let's
go ahead and get started with the installation
444.16 -> okay so the first thing that i want
to do is just verify that i have
447.52 -> java installed on my machine and to do that
i'm going to open up a terminal session
453.44 -> and in my terminal window i'm
going to type in java version
458.16 -> and you can see in the output of this command
that i have the open jdk version 11 installed on
462.88 -> my machine so if you don't have java installed
on your machine you'll want to make sure that
467.76 -> you go ahead and install either version 8 or
version 11 of either the jdk or the java runtime
475.2 -> environment before proceeding with the tutorial
so now that i've verified the version of java
480.24 -> that's installed on my machine i'm going to open
up my browser and i'm going to search for jenkins
489.12 -> in in the first link jenkins.io i'm
going to select the download link
495.84 -> and in the download page i'm going to
scroll down to where i see the generic
500.32 -> java package which is the war file and i'm
going to go ahead and download this package
508.08 -> and click save file and i'm going to open
the containing folder and i'm going to move
516.72 -> this jenkins.war file into my home directory if
you would like to run jenkins from a different
524.56 -> directory that's fine i'm just going to put
it in my home directory for my own convenience
529.76 -> now that i have the war file in the home
directory i'm going to navigate back to my
534.64 -> terminal window and in my terminal window
i'm already inside of my home directory
541.28 -> so if i do an ls i can see the jenkins.war file is
in direct in the directory and all i need to do to
549.52 -> start jenkins is uh invoke java pass in the
dash jar option and then the name of the
559.44 -> war file so we're going to say jenkins.org
and that will start the jenkins server and
567.52 -> this command is blocking so it's not going
to return back to the command line as long as
572.48 -> jenkins is running and jenkins by default is going
to be running unless we were to specify in the
580.16 -> in the invocation to java pass in parameters
to the program uh jenkins will by default
588.24 -> start running on localhost port
8080 so if we navigate to localhost
596 -> port 8080 what we should see is the startup
menu with jenkins and sure enough we see the
603.52 -> first the first startup page for jenkins is to
unlock jenkins so in order to proceed we have to
614.08 -> secure the initial admin password which is
provided to us in the output of the java command
621.36 -> when we start up the jenkins server so you'll
notice here it says please use the following
626.08 -> password to proceed to installation so all i need
to do is just copy that password and this password
633.76 -> is also located inside of this directory so
dot jenkins secrets initial admin password
642.72 -> so i have that copied i'll select continue
648.56 -> and then on the next page we can
customize jenkins to some extent
653.44 -> using plugins so as it says here plugins
extend jenkins with additional features to
658.8 -> support different needs and it's best to install
the suggested plugins if we wanted to we could
665.76 -> select a subset of plugins ourselves but in our
case we'll just select the suggested plugins
674.96 -> so jenkins is now installing all of the most
popular plugins that are available with jenkins
681.92 -> and a couple that i'd like to point out here is
the pipeline plugin which we will use in this
688.16 -> tutorial series the git plugin which will
install git on this jenkins server and will
694.88 -> allow jenkins to communicate to source
code management systems that are using git
710.16 -> okay so now that the plugins have been
installed we can create our first admin user
714.96 -> and the first admin user that i'm going to
create the username is just going to be moss
723.84 -> i'll type in a password here and for
726.88 -> the full name i'll just continue with moss
and then i'll enter an email address here
734.96 -> okay and then i'll click save and
continue now if we wanted to change our
742.48 -> our instance configuration and select a
different jenkins url we could do so here
747.28 -> i'm going to leave it as the default localhost
8080 and i'm going to select save and finish
754.88 -> and then i click start using jenkins and we
should be brought to the jenkins dashboard
761.92 -> so now we're at the jenkins homepage and i'd
like to get you familiar with the jenkins ui
767.2 -> and introduce you to some key components
of the jenkins interface so to facilitate
773.28 -> automation tasks jenkins has what
are known as jobs or jenkins jobs
779.36 -> and anytime you need to perform a task using
jenkins you need to create a jenkins job
785.52 -> and there are various types of jenkins jobs that
you can create and those jobs are listed under the
792.32 -> new item page here so let's go ahead and navigate
to the new item page so on this page we can create
798.64 -> a new item in jenkins and we can provide a
name for that item we can say test job here
807.68 -> and after we provide a name we can select what
kind of a job or what kind of an item this is
816.32 -> and the first option that we have is a freestyle
project and a freestyle project is really for
823.52 -> simple uh software development workflows it's for
simple projects and code bases where you might
831.6 -> not have a large number of steps to build and test
your software the next item is pipeline jobs and
839.92 -> pipeline jobs are good for more complex software
development workflows workflows that include
846.56 -> build tests and deployment steps but also might
include building multiple code bases rather than
854.56 -> just a single code base or a single repository
and one of the benefits of the pipeline jobs
860.16 -> is that we can store these complex steps as code
and we can write a file called a jenkins file and
867.76 -> that jenkins file will outline all of these steps
that we need to take in our software development
873.2 -> workflow in order to build test and deploy our
software product and later on in this tutorial
880 -> series we'll have a dedicated video covering
pipelines and how to create a pipeline job
886.48 -> the next item are multi-configuration projects
and these jobs are meant for pipelines targeting
892.88 -> multiple baselines or multiple platforms
so for instance you might offer a software
898.32 -> product like a mobile app but that mobile app
is offered on not only android but also ios then
905.04 -> you need to uh then you need to have a software
development workflow that includes testing on both
910.8 -> ios platforms and android platforms and this
multi-configuration project would help you do that
917.12 -> the next item in the list technically isn't
a job it's simply a container that stores
923.2 -> other items it could be a nested folder
or it could be a job inside of a folder
928.24 -> it's a way of grouping jobs into a directory-like
structure the next item is the github organization
936.24 -> item and i'm not sure why it shows up twice here
but the github organization item comes from the
942.8 -> github branch source plugin and this plugin
allows jenkins to scan a github user accounts
950.08 -> repositories or a github
repositories in github and for each
958.48 -> repository in the organization or the
user account that contains a jenkins file
964.32 -> jenkins will automatically create a job for that
repository and the plugin will also scan branches
971.04 -> of a github repository and for each branch that
contains a jenkins file it will also create a
977.28 -> dedicated job for that jenkins file and for the
last item here the multi-branch pipeline job
984.16 -> it's somewhat similar to the github
organization because it allows you to define a
991.04 -> code base which might not be located in
github maybe it's located in gitlab or another
998 -> source code management system for instance and
when you set the code base that you want this
1005.36 -> job to scan it will scan each of the branches in
that code base and for every branch that has a
1011.36 -> jenkins file in it it will automatically create
a jenkins job dedicated to that branch so now
1018.8 -> that we're somewhat familiar with the types
of jobs that we can create in jenkins let's
1023.2 -> navigate back to the dashboard and the next
key component of the jenkins interface that
1029.6 -> you should be familiar with is the manage jenkins
page so in the manage jenkins page we can control
1036.4 -> just about every aspect and every configuration
there is associated with our jenkins instance
1043.12 -> so let's go ahead and take a look at
what's contained inside of this page
1047.28 -> so in the first section of the manage jenkins page
we have the system configuration and under system
1054 -> configuration we can select configure system the
configure system page is the central place where
1061.6 -> you can update the configuration of jenkins and
you can also update the configuration of plugins
1067.12 -> as well on this page so one configuration
here that is worth noting is the number of
1072 -> executors and you can see here that the number
of executors is set to two when a jenkins job is
1079.52 -> ran we call a running instance of a jenkins job
a build so a jenkins job can produce a build
1087.04 -> and in order for a build to execute it needs
an executor an executor is essentially a thread
1093.76 -> that can execute the instructions outlined in
a particular build right now i've configured
1100.4 -> this jenkins instance with two executors which
means that i can have up to two builds running in
1107.68 -> parallel so it could be two builds of the same
job or it could be one build for one job and
1114.72 -> another build for a different job but i can have
a maximum of two builds running in parallel so
1122 -> if i were to increase the number of executors to
you know like 50 then i would have essentially 50
1128.56 -> available threads that i could schedule builds on
and i could have up to 50 jobs running in parallel
1134.96 -> now do you want to set the number of executives
that high probably probably not unless you have
1141.52 -> a large amount of resources when i say resources
i mean cpu and memory and and disk space as well
1150.72 -> because as you increase the number of executors
you're also potentially increasing the resource
1158.24 -> usage that's happening on your jenkins
instance so you need to be very careful
1162.08 -> with this configuration setting and in my
case i'm going to leave it at two another
1167.76 -> configuration that's also worth pointing out is
the home directory or the jenkins home directory
1172.8 -> which right now is in home moss and then dot the
dot jenkins folder the dot jenkins folder contains
1180.8 -> all of the data related to this particular jenkins
instance it contains all the jobs metadata the
1188.64 -> the artifacts of particular builds um and
if i were to delete this dot jenkins folder
1196.24 -> i'm essentially blasting this jenkins instance
away all of the uh all of the data associated
1202.56 -> with this jenkins instance would be gone and if
i were to delete that dot jenkins folder and then
1208.48 -> rerun that java command to start jenkins it
would essentially be a fresh uh jenkins instance
1215.44 -> and as i scroll down in the configure system
page you'll see other settings like the jenkins
1221.6 -> where jenkins is located in the jenkins
url but you'll also see configurations for
1229.92 -> particular plugins for instance the github plugin
which allows me to add github servers these might
1236.08 -> be the github server out on the public internet
github.com or it could be an on-premise instance
1242.56 -> of a github server you know on your inter
internal corporate network so let's navigate
1248.96 -> back to the manage jenkins page and then we'll
navigate to the global tool configuration page
1256.16 -> and the tool configuration page allows us
to specify installations or versions of
1261.52 -> tools that we would need in order to build
and test our code inside of a jenkins job
1267.12 -> so for instance we can specify a particular
version of the jdk to be installed and we
1272.32 -> can even add multiple versions of the jdk so that
we can compile java code inside of a jenkins job
1279.92 -> and we can also specify a particular git
installation so that jenkins can clone down
1286.32 -> a code base and build a particular code base from
a source code management system that's using git
1292.72 -> uh and there's other tools as well that we can
add installations for like gradle and and maven
1299.12 -> so coming back to the manage jenkins page uh under
system configuration we can also manage plug-ins
1307.68 -> that are installed in jenkins so from the managed
plug-ins page we can update plugins we can see uh
1314.64 -> what plugins are installed on the machine and we
can also search for plugins that are not installed
1321.92 -> and there are hundreds of plugins that extend
jenkins functionality that we can install
1327.68 -> through this uh through this page so let's
navigate back to the manage jenkins page
1333.76 -> and then under the security section i'm
going to select configure global security
1339.28 -> and on this page we can specify the method by
which users would authenticate to this jenkins
1346 -> instance and in our case jenkins is using its own
user database to authenticate users and right now
1354.8 -> in this database there are only two users there's
the admin user and then there's one other admin
1360 -> user uh called moss which i'm currently signed
in as and these two users exist uh inside of this
1368.4 -> jenkins owned database now we can utilize other
methods of authentication for instance if this
1375.36 -> jenkins instance was inside of a corporate network
that utilized ldap we could also integrate this
1382.32 -> jenkins instance into the the ldap service
in our corporate network in addition to
1389.12 -> configuring an authentication method we can
also select a uh an authorization strategy
1396.16 -> like matrix-based security which
will allow us to define more granular
1404.88 -> authorization levels inside of our jenkins
instance now let's navigate back to the manage
1410.16 -> jenkins page and under the security section
we also have manage credentials and the manage
1417.52 -> credentials page allows us to store credentials
that jenkins might need in order to to communicate
1424.16 -> with various services during a particular
jenkins build for instance when a jenkins
1429.12 -> build starts it typically has to clone down a
code base from a source code management system
1434.16 -> and in order to do so it has to authenticate
with the source code management system and
1439.28 -> oftentimes it'll do so using an ssh key pair and
you can store the private key of the ssh key pair
1447.76 -> in this manage credentials section of jenkins so
that when the build runs it will reference the
1454.08 -> private key stored in in the manage credentials
page uh in order to authenticate with the source
1460.56 -> code management system and clone down the
repository to the local jenkins workspace
1465.68 -> and from the security section you can also create
delete and modify users that are able to log into
1471.6 -> the jenkins instance and from the manage jenkins
page we can also monitor the jenkins instance
1477.2 -> uh using the pages listed under status information
we can look at the system log we can also
1483.76 -> review the resource utilization
like cpu and memory that the jenkins
1490.16 -> server is using on this particular machine and
we can also perform administrative tasks like
1497.36 -> uh restarting the jenkins instance or shutting the
jenkins instance down so hopefully you're a little
1503.36 -> more comfortable now navigating the jenkins
interface and in the next video we're going
1508.56 -> to install and configure the maven plugin so i'll
see you in the next video and thanks for watching
1521.2 -> hey what's up everybody my name is moss and
welcome back to our tutorial series on jenkins
1526.16 -> by now you should have a good understanding of
what jenkins is and you should also be familiar
1530.32 -> with some of the key elements of the jenkins
interface in addition you should have a jenkins
1534.48 -> instance up and running if so you're ready
for the next topic in this video we're going
1539.92 -> to install and configure the maven plugin on our
jenkins server so first what is the maven jenkins
1547.28 -> plugin the maven plugin is an open source jenkins
plugin that supports maven 2 and maven 3 projects
1554.48 -> and this plugin adds an additional job type to
jenkins called a maven project if you recall from
1560.08 -> the previous video i walked through the new item
page which listed all the possible job types you
1565.6 -> could create in jenkins and this plugin adds an
additional job type to that list on the new item
1571.84 -> page called maven project and this maven project
job type provides an advanced integration between
1578.48 -> maven and jenkins but the question is why use
the maven plugin when we could also invoke maven
1585.12 -> inside of a freestyle project the maven plugin
greatly reduces the configuration required for
1590.64 -> maven projects inside of jenkins and the plugin
enables post-build deployment of binary artifacts
1597.04 -> that are produced during a maven build in addition
the plugin provides graphical test reports
1602.16 -> directly in the jenkins ui it also supports
incremental builds so as not to waste resources
1608.32 -> we can also build modules in parallel and
distributed across executors and jenkins nodes
1614.56 -> the plugin also provides an additional
build trigger in the maven project job type
1619.36 -> if it's enabled jenkins will parse the pom
files of the current project if any of the
1624.64 -> dependencies listed in the pom file are built on
this jenkins instance then jenkins will set up
1630.64 -> a build dependency relationship so that any time
the dependency job is ran any downstream jobs that
1638.64 -> have that dependency listed in their pom file will
also be triggered to run now that we have a better
1644.56 -> understanding of what the maven plugin does let's
go ahead and install it on our jenkins instance
1650.32 -> okay so the first thing that i want to
do is navigate to the manage jenkins page
1655.68 -> and under system configuration i'm going to
navigate to the global tool configuration page
1663.12 -> and i'm going to scroll down to maven and
i'm going to select add maven installation
1671.44 -> and we'll give it a name we'll call it maven 3
1675.6 -> and i have the option to either install this
automatically or i can specify a pre-existing
1683.28 -> installation of maven on this machine so in
the maven home field i would just specify the
1688.96 -> directory where maven is installed on this machine
i don't have maven installed on this machine so
1694.32 -> i'm just going to select install automatically and
the default installer is installing from apache
1700.96 -> and then i have the option to select which version
i want to install in this case the latest version
1705.76 -> is already selected so i'm going to leave it as is
and since i selected install automatically during
1712.56 -> the first build of a maven project on this jenkins
instance jenkins will download and install maven
1719.6 -> so the first build of a maven project on this
jenkins instance might take a little bit longer
1724.48 -> because it's downloading maven but all following
builds won't take as long because maven is already
1730.16 -> installed on this jenkins instance so now that
i've specified install automatically i'm going to
1736.48 -> select save and in the manage jenkins page i'm
going to navigate to the manage plugins page
1745.12 -> and i'll select the available tab and
we're going to search for the maven plugin
1753.76 -> okay and it's the first result here called
maven integration i'm going to select that
1761.28 -> and then i'm going to select
install without restart
1765.28 -> and now that it is downloaded and installed i'm
going to select restart jenkins when installation
1772.56 -> is complete and no jobs running and so now
jenkins is restarting and when it reloads
1778.72 -> we should be able to see the maven project
job type shown in the new item page
1788.96 -> okay so i'm going to go ahead and log back in
1798.08 -> and i'm going to navigate back to the dashboard
1804.4 -> and from the dashboard i'm
going to select a new item
1809.92 -> and you'll notice below the freestyle project
we now have a maven project job type in addition
1817.6 -> to the other jobs that we can create in this
jenkins instance so i'll go ahead and create
1822.8 -> a sample project and we'll just call it test
maven and i'm going to select the maven job
1830.88 -> maven project job type and
i'm going to select okay
1836.96 -> and there's a couple of things i'll point out
in this configuration page the first is under
1841.52 -> build triggers so the first option here is the
additional build trigger that i was talking about
1847.36 -> in the powerpoint slide so we can add a build
trigger to build this maven project whenever
1854.48 -> a snapshot dependency is built and so this is the
dependency that is listed in the pom file for this
1861.12 -> particular maven project and the other key element
of this configuration page is under the build
1866.56 -> section and here we specify where the root
palm is located and we can also specify
1873.68 -> maven goals and options in this field so
for instance i could say clean compile
1880.32 -> and test here we can also add pre and post steps
as well and in an upcoming video we'll use an
1887.76 -> actual maven project with this jenkins job type
but before we do that we'll want to integrate this
1894.56 -> jenkins instance with our github account so that
jenkins can clone down the maven project code base
1901.36 -> locally to the jenkins workspace and build
it so what we'll target in the next video
1906.08 -> is setting up the integration between this
jenkins instance and our github account we have
1910.48 -> the maven plugin installed and ready to go on this
jenkins instance so i'll see you in the next video
1923.2 -> hey what's up everybody and welcome back to our
tutorial series on jenkins in the last video i
1928.24 -> walked you through the installation of the maven
integration jenkins plug-in before we utilize
1933.2 -> that plugin we're going to build some additional
automation on our jenkins instance so let's take
1938.24 -> a look at the next topic in this video we're going
to integrate our jenkins instance with our github
1944.96 -> account you probably remember this diagram from an
earlier video describing the jenkins architecture
1950.96 -> what we'll be focusing on in this video is
automating the trigger build and publish results
1956 -> steps in this sequence diagram after automating
these two steps when a developer pushes a commit
1961.6 -> from their local machine to a github repository
or when they make a commit directly in github
1967.76 -> what should happen is github should trigger a
jenkins build for that github repository after
1974.16 -> the build is triggered jenkins will clone down the
github repository to its local workspace and once
1979.92 -> the build finishes jenkins should automatically
publish the results back to the github repository
1985.92 -> so what are some of the benefits of integrating
jenkins and github some of these benefits you may
1990.64 -> have already guessed but the first benefit is that
it gives jenkins the ability to clone a code base
1995.84 -> down to the local workspace so that it can
build and test the code the second benefit
2000.88 -> is that github will push new changes to jenkins
and trigger builds rather than having jenkins
2006.96 -> consistently pull github repositories for new
changes polling for new changes too frequently can
2013.44 -> be quite resource intensive on the github server
and the github api will actually rate limit you if
2019.36 -> you pull too frequently the third benefit is that
jenkins will be able to perform github operations
2025.68 -> which would include doing things like publishing
the build result to a github pull request
2030.4 -> and to individual commits there is one key
prerequisite that i would like to point out
2035.76 -> for this integration in order for the integration
to work as described github must be able to send
2041.44 -> data to jenkins and since i'm using a github.com
account that means that the jenkins instance
2047.2 -> must have a public ip the only exception to this
is if you're working on a jenkins instance that's
2053.28 -> inside of your corporate network and you have an
on-premise github instance also inside of your
2058.8 -> corporate network now that we've covered those
details let's get started with the integration
2064.56 -> okay so the first thing that i want to do
is navigate to my github account which i'm
2068.32 -> already in my account and then once you're in your
github account you're going to want to go up to
2073.44 -> the the profile drop down and then select
settings and under settings we're going
2081.92 -> to navigate to developer settings and we're
going to navigate to personal access tokens
2089.52 -> and we're going to generate a new token a
new personal access token okay we'll call it
2099.36 -> jenkins and after giving it a name we have to
select scopes for this token and what scopes
2110.08 -> do is they provide a level of authorization
to uh your to what your github account has so
2117.04 -> for instance your github account has access to
all of your private repositories for instance
2122.08 -> and you can grant this token access to your
private repositories or you may not want it uh to
2128.48 -> have access to your private repositories maybe you
only want it to have access to public repositories
2135.12 -> and as we select each one of these scopes we're
adding additional levels of authorization to our
2141.28 -> github account for this particular token and
for this integration to work i'm going to be
2147.04 -> using a public github repository so the only
scope that i need to select in this case is
2152.64 -> the public reposcope which will grant this token
access to public repositories i'm going to leave
2160.4 -> all of the other scopes unchecked and then
i'm going to select generate token now on this
2167.76 -> next page the token value is presented to us and
you're going to want to copy this value maybe
2176 -> save it in a in a text file temporarily but not
permanently but at least copy it to your clipboard
2182.56 -> because we're going to use it inside of jenkins so
i'm going to select the clipboard here which will
2189.28 -> copy the token value and i'm going to navigate to
my jenkins instance which i already have pulled up
2197.2 -> and in jenkins i'm going to select manage jenkins
2202.24 -> and then under system configuration
we'll go to configure system
2208.96 -> and then i'm gonna scroll
down to the github section
2213.6 -> okay and this github section is for the github
plugin which should have been automatically
2220.32 -> installed if you selected install recommended
plugins when uh installing jenkins so the two
2226.96 -> plugins that are required for this integration uh
are the github plugin and the git plugin and both
2233.52 -> of those are installed as part of the recommended
plugins when you're first installing jenkins and
2240.24 -> in the github plugin configuration we can add
github servers that we want to authenticate with
2246.72 -> and uh the one that we're going to authenticate
with is already automatically filled out here
2252.96 -> so we're going to be authenticating with the
public github api and i'm just going to call it
2259.2 -> github and once we specified a name and the
api url we also have to specify credentials to
2270.72 -> authenticate with our github account right so we
need to provide credentials to authenticate with
2278.24 -> our github account and this is going to be
our personal access token that we just created
2283.68 -> so i don't have any credentials created on
this jenkins instance right now so what i'm
2289.28 -> going to do is i'm going to select add and i'm
going to select the jenkins credential provider
2296.24 -> and on the add credentials page i'm going
to specify the kind of credential that i
2301.36 -> want to create which in this case is going to be
secret text okay so the personal access token is
2308.8 -> considered a secret text credential okay i'm
going to leave the scope the same and then
2315.6 -> for the secret i'm going to paste in the personal
access token value and we'll give it an id we'll
2324.32 -> call it github p-a-t i'll leave the description
blank and then i'll select add okay now in the
2333.44 -> drop-down we have uh the p-a-t credential that
we can select so i'm going to go ahead and select
2340.56 -> that credential now once we've added our
credentials we can test the connection
2345.28 -> to the github api so i'm going to
go ahead and click test connection
2352.8 -> and you can see that it says credentials verified
for user tech with moss and then it specifies the
2358.08 -> the rate limit and how many uh api calls i
have left so uh it's set at 5000 and i just
2366.16 -> used one to test connection so i have 4999
api calls remaining before i'm rate limited
2374.96 -> and the last configuration here is the manage
hooks configuration and when this is checked
2380.24 -> jenkins will uh basically automatically add the
jenkins web hook endpoint to the github repository
2388.16 -> so that github can then send data back to jenkins
what we're going to do is we're going to manually
2394.4 -> add the web hook to our github repository
rather than have jenkins automatically do it
2400.4 -> so i'm going to uncheck this and then i'm
going to select save for this configuration
2408 -> and now that we've added that personal
access token to this jenkins instance
2411.84 -> jenkins should be able to communicate to github
and publish build results to a github repository
2418.64 -> but one thing to note is that i used my personal
github account credentials uh so that jenkins
2425.36 -> could authenticate with github but it is a best
practice to use something like a service account
2430.16 -> or a generic account maybe an account that's
called like jenkins-ci or something like that and
2436.88 -> then use that account's credentials to facilitate
this particular automation the next step is to
2443.04 -> create an ssh key pair and we're going to add the
public uh key to our github profile and then add
2449.84 -> the private key to this jenkins instance and that
will allow this jenkins instance to clone down
2456.48 -> repositories to the local jenkins workspace so
any github repositories that my github account
2463.76 -> has access to this jenkins instance will also
have access to and be able to clone down when
2469.52 -> a build starts so i'm going to open up a git
bash session to generate the ssh key pair
2476.96 -> and in my get bash window i'm going to
use ssh keygen to generate the key pair
2486.72 -> and i'm going to accept all of the
defaults it asks me to overwrite
2493.28 -> my keeper i'm just going to do
that and so i generated a key pair
2497.68 -> and i'm going to cat the public key
2508.8 -> okay so there's my public key and i'm
going to copy that uh that public key
2516.96 -> to my clipboard and then i'm going
to navigate back to my github profile
2523.04 -> and in the settings menu of my github profile
i'm going to go down to ssh and gpg keys
2532.48 -> and i'm going to select new ssh key
i'm going to paste in my public key
2540.4 -> and i'll give it a name i'll just call it jenkins
2546.64 -> public key
2551.12 -> okay so that added the uh the public key to my j
uh to my github profile and i'm going to navigate
2559.04 -> back to jenkins and i'm going to open up
the get bash window again now i'm going to
2566.48 -> cat the private key and i'm going to
copy the contents of the private key
2574.64 -> okay so this is the private key
2579.36 -> and i'm going to go ahead
and copy that to my clipboard
2588.48 -> okay and in jenkins i'm going
to navigate to manage jenkins
2596.8 -> and then i'm going to go to the security section
and i'm going to select manage credentials
2604.16 -> i'm going to select jenkins i'll select global
and then i'm going to select add credentials okay
2612.88 -> and the kind is going to be uh ssh
username with cr uh private key
2621.12 -> i'll leave the scope as is and
we'll call it github private key
2629.44 -> okay i'm going to leave the username blank and
2632.24 -> then for the private key i'm
going to enter that directly
2638.96 -> okay so i'm going to paste the private key in
there i didn't create a passphrase for this
2644 -> particular key so that's all i need i'm going
to select ok ok so we added the private key to
2652.56 -> jenkins so jenkins when a build starts for a
particular github repository it should be able
2659.84 -> to clone down the repository using this private
key that we just added so i'm going to go back to
2666.8 -> the jenkins dashboard so now that we've added the
ssh private key to this jenkins instance let's go
2673.36 -> ahead and create a new jenkins job so i'm going to
go to the new item page and we'll call it test job
2682.16 -> and i'm going to select freestyle
project and then i'll select okay
2692 -> all right and in the source code management
section i'm going to select git and then it
2701.92 -> prompts me to enter the repository url so this
is going to be the url of the github repository
2708.48 -> and i have created a very simple github repository
all it has is a single readme file in it
2715.12 -> so i'm going to navigate back to my github profile
2720.08 -> okay i'm going to select my repositories and then
i'll select this repository which is the one that
2728.56 -> i created it's just a very basic repository
with just a readme file uh in the repository
2736.88 -> and i'm going to select the uh the code tab here
and it gives me the url so notice how i can select
2746.48 -> different urls i can select an https url or an
ssh one make sure that you select the ssh one
2753.76 -> because we're using an ssh key pair to clone down
this repository so we need the ssh url and not the
2761.44 -> https url so i'm going to select the ssh
url i'm going to copy that to the clipboard
2770.56 -> and i'm going to navigate back to jenkins and
i'll paste that in okay so it says fail to
2777.92 -> connect right now and it says permission denied
so i haven't specified the credentials that i
2784.24 -> want to use in order to clone this repository down
so in the credentials section i'm going to select
2790 -> the private key that was just created and it
defaults the username so i remember that i didn't
2796.64 -> enter a username here it automatically entered a
username for me and so i'm going to select that
2804.88 -> and notice that the error disappears after
selecting the credentials which means that it
2810.24 -> was able to authenticate uh successfully so it can
clone down this repository the next configuration
2817.36 -> is under branches to build i'm going to specify
the main branch since that's the the only branch
2823.68 -> i have in my github repository and once i've
specified that i'm going to scroll down to
2830.24 -> the build triggers section and what the
github plugin provides is an additional
2839.2 -> build trigger and it's this one right
here it's github hook trigger for git
2843.6 -> sem polling and it says here if jenkins
receives a push github hook from a
2850.4 -> github repository that's defined in the git sem
section it will trigger the get sem polling logic
2859.2 -> okay basically what this means is that if
github uh receives a push from a developer
2865.76 -> so a developer pushes a commit up to a github
repository github will then automatically
2873.2 -> trigger this particular jenkins job to
build if this build trigger is selected
2880 -> so we are going to go ahead and check that
build trigger since we want that behavior
2884.88 -> the next configuration that we're going
to set is under post build actions
2889.04 -> i'm going to select add post build action
and then set github commit status okay
2896.8 -> and what this action will do is when the build
finishes jenkins will communicate the build result
2903.36 -> back to the github repository and it will set the
build status on the individual commits that were
2911.84 -> built during this particular jenkins build as
well as the pull requests if there is an open
2918.64 -> pull request for the commits that were
built in this particular jenkins build
2924.24 -> so i'm going to leave these two fields as their
default values and then under uh the what section
2932.32 -> i'm going to specify the status result based
on one of default one of the default messages
2939.2 -> and statuses so this status result basically
allows me to manually define like what the
2945.36 -> status message will say uh based on the build
results so if i select it here result better
2951.04 -> than or equal to let's say um you know success i
can provide a custom success message but in for
2960.4 -> my case i'm just going to select uh the default
messages in status uh we don't necessarily need
2966.8 -> uh custom messages in this particular case
and this back reference will provide a link
2973.28 -> directly back to the build inside of github so
that should be all the configurations we need in
2979.28 -> this particular job so i'm going to go ahead and
select save so now that we've created the jenkins
2985.36 -> job there's one last configuration that we need to
make and it's inside of github repository so i'm
2991.6 -> going to navigate back to my github repository and
in the repo i'm going to select the settings page
3001.52 -> and under settings i'm going to navigate to
the web hooks section okay and web hooks allow
3009.04 -> external services to be notified when certain
events happen in this particular repository so i'm
3015.68 -> going to select add webhook and the first field
that is required is the payload url and this is
3023.68 -> the url endpoint that github will send data to and
in our case it's going to be our jenkins url with
3033.12 -> a special endpoint added onto the base jenkins url
so i'm going to navigate back to jenkins i'm going
3040.8 -> to copy the base url which is right here i'm going
to paste that in and then i'm going to add the
3049.28 -> the endpoint for github web hooks which
is github hyphen web hook okay and then
3056.56 -> forward slash the content type i'm going to
select as json i'll leave the secret blank
3064.56 -> and then it allows me to select
which events i would like to
3069.04 -> trigger this web hook for and i can use just
the push event i can say for any event send me
3075.36 -> everything or i can say let me select individual
events so maybe instead of the push event i want
3084.48 -> this web hook triggered anytime a pull request
is opened and this particular selection will
3093.36 -> allow me to do that so if i select this then any
time a pull request is open closed reopened etc
3100.88 -> an event will be triggered for this web hook and
that data that event will be sent to jenkins and
3108 -> it will be sent to this particular endpoint
that we provided here okay and i'm going to
3113.44 -> leave it as is with just the push event being
sent to the endpoint that's really all we need
3120.8 -> right now and i'll leave it as active and
then i'll select add web hook okay and when
3129.28 -> you select add web hook it should automatically
test the connection so i'm going to go back into
3134.96 -> the web hook and you'll notice that under recent
deliveries we have this little check mark and it
3141.2 -> tested the the web hook and that was successful
we got a successful uh 200 response back from
3148.96 -> jenkins so we configured this web hook correctly
so now that we've added the hook we should be
3154.64 -> able to make commits locally on our machine and
push them to github or make commits directly in
3161.68 -> the github interface and both of those actions
pushing commits as well as making commits in the
3167.76 -> github interface should trigger our jenkins test
job to run a build for this particular repository
3176.32 -> so let's go ahead and try it out i'm going to
navigate to the code tab and i'm going to make a
3181.84 -> commit directly in the github interface and i'm
going to just edit the readme file and just say
3192.8 -> okay and then for the commit message
i'll just say testing jenkins
3200.64 -> and before i select commit changes i want to
show you that our test job currently doesn't
3206.16 -> have any jobs that have ran or any builds that
have previously ran right so after i select
3213.36 -> commit changes we should see a build running
in this uh jenkins job okay so i'm gonna select
3221.28 -> commit changes and let's take a look back at our
jenkins job and you'll notice that we have a build
3230.32 -> currently pending in the jenkins job and it's
already finished so if i select refresh we can
3237.12 -> take a look at the jenkins job and uh it success
successfully cloned down the test repo from github
3247.04 -> there wasn't really anything in the repo and there
wasn't anything to build any code to build or test
3252.4 -> so it didn't really do anything except clone down
the repository and then it performed the post
3259.68 -> build action of setting the github commit status
in github so what does that look like in github
3266.8 -> let's navigate back to the github repository
and i'm going to select the latest commit here
3275.44 -> and you'll notice that next to the commit
message here we have this small check mark
3282.96 -> that check mark indicates the status of that
commit and it says all checks have passed
3288.4 -> and then we also get a back reference
3292.32 -> to the jenkins job itself uh so this details um
hyperlink goes back to the jenkins job so let me
3301.6 -> click that and you'll notice that you'll see
here that it goes back to to the build in jenkins
3309.84 -> and i'll go ahead and navigate back to the github
repository so this works for individual commits
3316.16 -> if i were to look at the list of commits
for a particular branch you'll see that
3325.68 -> commits that triggered a build if the build was
successful they'll get this small check mark next
3331.84 -> to them and it says you know build number one
succeeded in this amount of time and you get a
3336.8 -> back reference to the jenkins build itself this
also this status also pops up in pull requests
3344.88 -> uh so if you have a pull request for a commit or
multiple commits then jenkins will also post the
3352.08 -> status inside of the pull request and let's try
that out real quick i'm going to navigate back to
3358 -> jenkins and in jenkins i'm going to navigate to
the job and i'm going to make one configuration
3364.96 -> change it's going to be to the branch specifier
and i'm just going to leave this blank so
3373.44 -> this will build for any branch not just
the main branch if i leave it blank
3381.28 -> so i'm going to navigate back to github
and i'm going to go to the code tab
3389.04 -> and in the code tab i'm going to create
a new branch we'll call it jenkins
3396 -> test branch i'll select create branch and i'll
make a small modification to the readme file
3411.68 -> and i'll commit these changes and as soon as i
commit the changes this should trigger a build
3419.04 -> in our jenkins job and it will trigger a build
since i just modified the jenkins job to build any
3427.68 -> of the branches in this repository not just the
main branch so i'm going to navigate back to
3434.24 -> the code tab and in the code tab i'm going to
select compare and pull request for my branch
3442.24 -> i'll leave everything as is and
then i'll select create pull request
3448.56 -> and you'll notice that on the pull
request page if i scroll down here
3452.08 -> we have this status check and it says all
checks have passed one successful check and if i
3459.68 -> click show all checks it will show me the
test job name and it specifies that build
3466.72 -> 2 succeeded in half a second and then it
provides a back reference back reference to
3473.68 -> the build itself so if i click details it
takes me directly to build number two okay
3481.76 -> so that about wraps it up for this integration
as you can see it's a very useful integration for
3486.88 -> optimizing the ci cd process i hope you enjoyed
this video and i'll see you in the next one
3500.96 -> hey what's up everybody and welcome back to our
tutorial series on jenkins in the last two videos
3506.16 -> i showed you how to integrate github with jenkins
and i also walked you through the installation of
3510.88 -> the maven integration plug-in which laid the
groundwork for this video so let's take a look
3515.52 -> at the next topic in this video we are going
to create a jenkins job for a maven project
3521.6 -> i'll quickly recap some of the key
features of the maven project job type
3526.16 -> the maven integration plugin provides a new
job type in jenkins called a maven project
3531.76 -> and the maven integration plugin significantly
reduces the manual configuration required to
3536.8 -> set up a maven project in your jenkins
additionally the plugin provides test
3541.36 -> reporting directly in the jenkins interface
and with that let's go ahead and get started
3548.16 -> okay so the first thing that i wanted to do was
quickly walk through the maven project that we're
3552.64 -> going to build in our jenkins server and i have
the maven project pulled up in my github account
3559.36 -> it's called sample maven project and it's a very
basic java application and i actually generated
3565.76 -> this code base automatically using the maven quick
start archetype and if we take a look at the quick
3572.08 -> start archetype it will generate a sample maven
project for us with a very simple structure
3578.72 -> and if we take a look at the directory structure
it begins with a top level palm.xml file then we
3585.76 -> have the source directory and inside of the source
directory we have a single app class and then we
3592.56 -> also have a test directory which contains the
app test class that tests this app class so if
3601.36 -> we navigate back to the github repository we can
take a look at the app class and see what it does
3607.68 -> so if i navigate to the app class it's very simple
it just prints out hello world to the console
3614.8 -> and then if we go back to the test directory
and open up the app test class this is also
3624.08 -> very simple it's a junit a single junit test it's
a assert true with an always true condition so it
3632.64 -> should always pass so this is the code base
that we want to build in our jenkins instance
3637.68 -> so let's navigate to jenkins and we will create a
new maven project so opening up jenkins and then
3646 -> i'm going to select the new item page and
i'm going to call it test maven project
3657.2 -> and then i'll select the maven project
job type and i'm going to click ok
3668 -> and the first thing that we want to do
is set up our source code management
3672 -> and so i'm going to scroll down to the sem
section and then i'm going to select git and
3677.68 -> then we need the repository url and remember that
this is going to be the ssh url for the repository
3686.88 -> so i'm going to navigate back to the github
repository and i'm going to copy the ssh url
3697.68 -> and i'll paste that into the uh repository
field okay and i get a permission denied
3705.6 -> error which means that i haven't selected
the credentials to use uh to clone down
3710.56 -> this repository so i'm going to select my
ssh private key that was previously added
3719.44 -> and you can see that the error disappears
after selecting the private key
3726.4 -> the ssh private key the next thing that i'm going
to update in this configuration is the branch
3731.68 -> specifier i have only have the main branch in this
repository so i'm going to just update that to
3739.28 -> main and the next configuration that we're
going to update is the build triggers
3745.84 -> and you may remember me discussing this first
build trigger build whenever a snapshot dependency
3751.2 -> is built when we were first installing the maven
integration plug-in but essentially whenever
3756.8 -> this build trigger is checked any snapshot
dependency that is defined in this project's
3763.6 -> pom file is built on this jenkins instance so if
any other dependencies defined in the pom file
3770.4 -> are built on this particular jenkins instance then
those builds those dependency builds will trigger
3778.32 -> a build for this job that we're defining now
and although there aren't any dependencies being
3783.84 -> built on this jenkins instance for this particular
project i am just going to leave it checked since
3789.36 -> it's checked by default the next trigger worth
noting is the build after other projects are built
3795.52 -> trigger it's somewhat similar to the first build
trigger but when i have this trigger selected
3802.48 -> it allows me to specify a list of jobs on this
jenkins instance and when those jobs are built
3810.16 -> it will trigger a build for the current job that
we're defining and there is a second condition
3816.16 -> that i can specify here to trigger only if the
build in the project specified in this field
3823.36 -> are stable or i can trigger it even if the build
is unstable in these projects that i defined here
3829.44 -> or i can trigger it even if the builds fail in
the projects that i defined in this field this
3835.44 -> trigger might be useful if you have multiple jobs
and each job only performs like a single task
3841.44 -> and it's like a pipeline of jobs that you want to
run in succession but in this case we don't really
3850 -> need that and even if you did have multiple jobs
like that that are kind of like a pipeline of jobs
3856.56 -> it would be preferable to just write a pipeline
script and have a single pipeline job to handle
3862.64 -> those individual tasks so i'm going to
go ahead and uncheck this build trigger
3868.16 -> the next build trigger is build periodically and
this trigger allows you to schedule this job on
3876.48 -> a predefined cadence and you can use cron style
syntax in this field to specify how often this job
3885.52 -> will build so for instance if i wanted this job
to build every minute i would use this syntax and
3894.16 -> you can see here it says do you really mean every
minute uh when you say you know five stars there
3901.12 -> uh perhaps you meant uh hourly okay so this would
be the syntax for running this job hourly and i
3908.64 -> think this build trigger is particularly useful
when you use it for your release cycle cadence
3915.84 -> so for instance you might want to have like a
nightly build of your main branch or you might
3921.68 -> have a weekly build of your main branch or you
might have a release at the end of every sprint
3928.72 -> so maybe you want to schedule this for every two
weeks or every three weeks and i think that's
3934.24 -> where this build trigger is most useful in this
case i'm not going to utilize this trigger so i'm
3939.28 -> going to go ahead and uncheck it the next trigger
is the github hook trigger for get sem polling
3945.36 -> and this is the trigger that we set up in
the previous video so when this is checked
3950.88 -> anytime a developer pushes a commit to github or
makes a commit directly in the github interface
3957.36 -> an event is sent to jenkins that will trigger uh
this job for the code base that they they push
3964 -> that commit to and i am going to utilize it for
this maven project so i'm going to go ahead and
3969.36 -> check it and the last build trigger is pull sem
which is kind of the opposite of the github hook
3976.24 -> trigger because it allows you to schedule a
predefined cadence for jenkins to pull your
3984.24 -> source code management whether it be github or
another source code management system for new
3989.12 -> changes i've mentioned this in previous videos but
using this build trigger is kind of a bad practice
3995.36 -> you don't necessarily want to pull your scm
system uh if you do you want to do it infrequently
4002.48 -> maybe like once a day probably once a day would
be like the most frequent maybe once an hour but
4010.16 -> in general polling the sem system is bad because
you're consuming resources on the sem system and
4017.68 -> you're also consuming resources on this jenkins
instance to query or make a query to the source
4023.84 -> code management system to check if there's any new
changes so it's really a best practice to always
4030.48 -> set up if possible the github hook trigger if
you're using github or if you're using another scm
4037.2 -> system use some sort of web hook that will push
new changes to jenkins rather than having jenkins
4044.8 -> pull the sem system so i'm going to go ahead and
uncheck this pull sem option now remember we do
4051.28 -> have to set up the web hook inside of the github
repo if we select this option so after we save
4058.8 -> this new maven project we'll go ahead and add
that web hook to our github repository the next
4065.12 -> configuration that we want to set up is the build
configuration and under the build section we can
4072.24 -> specify where the root palm is located and here we
can leave this value as is since the pom file is
4082.08 -> at the directory of our maven project and on the
second field here we can specify goals maven goals
4089.92 -> and options so for instance i can specify clean
install in this field and if i were to leave the
4097.12 -> field blank it would perform an install by default
it would perform the install life cycle but i
4104.88 -> could also specify deploy here if i had a remote
repository that i wanted to send the generated
4111.92 -> artifacts to but i'm going to go ahead and leave
this as clean install so that should be the bare
4118.48 -> minimum configuration that we need for this
maven project so i'll go ahead and select save
4127.2 -> and before we build this project for the
first time i want to add the web hook to
4132.16 -> our github repository so i'm going to copy
the address here so we'll copy the port
4143.2 -> and then in the github repository we'll navigate
to settings and in settings we'll select webhooks
4152.16 -> add webhook and then the payload
url will be the url of the jenkins
4157.76 -> server and the github web hook
endpoint okay and i'll select json
4168.64 -> and we'll leave the default selection so
this will send the push event to jenkins
4174.8 -> and we'll leave it as active i'll select
add webhook okay and if i select the webhook
4182.96 -> we can see under recent deliveries
that it was a successful delivery
4188.08 -> so we know it's configured correctly and now
let's navigate back to our jenkins instance
4195.6 -> now let's build the project for the first
time so i'm going to select build now
4205.28 -> and let's take a look at build number one
4210.64 -> so it performed maven clean it compiled and
then it ran the single test case and the apt
4219.28 -> uh the app test class and then it performed the
uh install as well so it archived the snapshot
4231.68 -> jar in the local repository and what's
neat if we take a look back at the
4238.96 -> project page itself after the build
runs we get this test result trend
4245.6 -> which shows the duration of the tests on the
y-axis and then the build number on the x-axis
4252.88 -> so if i hover over this single data point here
we can see that build number one one test pass
4260.24 -> and zero tests skipped and zero tests failed
and additionally if i go into the build itself
4269.68 -> we also get kind of a test report inside of
jenkins so if i take a look at the test result
4277.28 -> we can drill down into the module the package and
then the test class itself and then look at all of
4283.52 -> the tests within a single within a single class
and take a look at whether or not they pass or
4290.4 -> failed and if the test failed then we can also
get the stack trace directly in this interface
4296.4 -> as well so we could see you know the stack trace
and get a little bit more details on the failure
4303.04 -> and from the build page we can also access
build artifacts so as you can see here under
4309.44 -> build artifacts i can download the
snapshot jar or the snapshot palm
4315.52 -> locally to my machine and this would be especially
useful if you wanted to perform manual testing
4321.04 -> after automated testing occurs on the generated
snapshot and just for the sake of it let's update
4327.52 -> our test case to fail just so that we can see what
the test report looks like when a test case fails
4335.04 -> so i'm going to navigate back to the github
repository and i'll navigate to our test directory
4344.48 -> and this will also exercise our web hook as well
or it should if our web hook is working correctly
4351.92 -> i'll open up the test class
4355.68 -> and i'll directly modify it in the github
interface we'll change that condition to false
4366.16 -> okay and then i will commit that change so let's
take a look back at our maven project in jenkins
4376.56 -> and let's see if it uh successfully
triggered a build and it took a little
4380.88 -> while for the jenkins interface to update
but it did trigger a build and as you can see
4387.28 -> for build number two it is unstable the yellow
mark indicates that it's an unstable build
4394.24 -> and unstable means that one or more test
cases failed and if we take a look at
4400.16 -> the test result trend we can also see that
build number two is represented in the graph
4406.56 -> and in build number two we have one failed test
case and i'll quickly open up the build number two
4415.12 -> page and if i select the test results you can
see the number of failures is listed up here
4423.52 -> that there was one failure and then it lists
the failed tests and if i expand this out i can
4431.28 -> expand the stack trace for this failed
test and it's a pretty simple one all
4435.84 -> it says is that there is an assertion error
because the condition that we selected was
4442 -> or that we added to this test case was false
so that's all i have for this video i hope you
4447.6 -> enjoyed it and in the next video i'm going
to walk you through the process of setting
4452.24 -> up a jenkins controller and jenkins agent
nodes so i will see you in the next video
4463.68 -> hey what's up everybody and welcome back to our
tutorial series on jenkins in the last video i
4468.88 -> showed you how to create a jenkins job for a
simple maven project and our jenkins server
4473.6 -> has no problem running this job or really any of
the jobs that we've created in the previous videos
4478.88 -> but in a corporate environment jenkins jobs might
consume a significant percentage of resources on
4484.64 -> the machine that's hosting the jenkins server
especially when there are many jobs ran in
4489.12 -> parallel so let's take a look at our next topic
that will help mitigate this challenge in this
4494.24 -> video we are going to configure jenkins controller
and jenkins agent nodes and before i walk you
4500.56 -> through the configuration steps i first want to
discuss the problem that we're trying to solve
4506 -> as software teams and their organizations
grow so does the need to scale jenkins
4511.28 -> in addition software teams may need to build and
test software on multiple platforms like windows
4517.44 -> mac os and linux and a single jenkins instance
will likely be unable to meet these requirements
4523.68 -> in order to meet these requirements we must
scale jenkins up and or out jenkins can support
4530.16 -> organizational growth as well as the need
for multi-platform build and testing through
4534.4 -> the use of agents jenkins agents are machines
that the jenkins controller can delegate the
4539.28 -> task of building projects to in a distributed
manner an agent node might be a windows machine
4544.96 -> a linux machine or some other platform that
supports java this allows multi-platform build
4550.64 -> and testing using the same jenkins server and it
also allows us to scale our jenkins out as needed
4556.8 -> all we need to do is add additional agent nodes
if we take a look at the architecture shown here
4562.16 -> the jenkins controller node is the jenkins server
that we've already configured in previous videos
4567.6 -> we will be adding a windows agent node in this
video after we've configured our jenkins agents
4572.8 -> the jenkins controller will be able to schedule
builds on jenkins agents according to the jenkins
4577.68 -> job configuration now that we've covered those
details let's get started so the first step to set
4583.68 -> up our jenkins controller in jenkins agent nodes
is to create an ssh key pair i have my terminal up
4590.64 -> already i'm using git bash and in git bash
i'm going to use the ssh keygen command to
4599.04 -> generate a new key pair and i'll call it azure
jenkins agent and i'll leave the passphrase empty
4611.12 -> okay so that generated a new key pair
and i'm going to cap the private key
4622 -> i'm going to copy the contents of the private key
4630.72 -> and then i'm going to navigate to jenkins and in
the jenkins controller i'm going to navigate to
4638 -> manage jenkins and then we'll
navigate to manage credentials
4646.16 -> we'll open up the jenkins credential store
and then global credentials and then i'm
4651.68 -> going to select add credentials and then the
kind of credential that we're going to use
4656.96 -> is ssh username with private key and we'll give
it an id we'll say it's azure jenkins agent and
4668.8 -> the username is going to be azure user and
then the private key will enter directly
4677.2 -> and i'll just paste the private key into
that field okay and then i'll select okay
4685.76 -> the next step is to copy our public key to the
machine that is going to be our jenkins agent
4691.52 -> hosted in azure and i already have an ssh session
open with that machine so i'm going to open up
4699.36 -> that session and i'm currently on the logged
onto the machine or the vm that will be running
4709.28 -> as a jenkins agent and i'm going to modify
the authorized the authorized keys file
4721.36 -> and add the public key that we just created
4726.8 -> okay
4732.48 -> so in the other terminal window
i'm going to cat the public key
4747.04 -> and i'll copy the public key value
4754.88 -> and i'll add this public key
to the authorized keys list
4762.32 -> and then we will save that file so now we should
be able to ssh or this jenkins instance should
4770.4 -> be able to ssh to this vm hosted in azure so we
can begin configuring this azure vm as a jenkins
4780.64 -> instance inside of our jenkins controller so i'm
going to navigate back to the jenkins dashboard
4789.04 -> and from here i'm going to navigate to manage
jenkins and then i'm going to select manage nodes
4796.16 -> and clouds so we're going to create one additional
node and i'm going to use this windows pc as the
4805.12 -> second node so i'm going to select new
node and we'll call it windows agent
4813.2 -> i'll select permanent agent even
though i do have the option to
4817.6 -> copy from an existing node and i'll select ok
i'll leave the number of executors at one and
4824.88 -> then i'll use the same remote root directory
i'll just call call it jenkins agent data
4834.48 -> and for labels i'll
4838.4 -> use the windows label usage i'll leave
usage as default and then the launch method
4846.24 -> will use launch agent by connecting it to
the master and one uh reason uh besides just
4853.6 -> to demonstrate this launch method uh one other
reason to use this launch method is because
4860.48 -> i'm on this windows pc is on my home network
and the azure vm is has a public ip and it's
4868.8 -> accessible so i can use the the ssh connect to
via ssh in that case because port 22 is open
4879.6 -> and the ip for that azure vm is public but for
this windows pc the ip address is not public and
4889.12 -> by using this launch method
i can start the agent program
4893.84 -> locally and then specify the ip address of the
controller and establish a connection an outbound
4900 -> connection to the controller that way since
the controller does have a public ip address
4905.28 -> i'll leave the rest of the configurations for this
launch method as default same for the availability
4913.84 -> and then i'll select save so now you can see that
the windows agent has been added but there is an
4920.4 -> x over the node indicating that jenkins is
not connected with it and if we click on
4927.12 -> the agent it says that the jnlp agent
port is disabled and agents cannot connect
4932.8 -> this way and it even tells us where we need to
go to update uh the configuration uh so that this
4940.08 -> uh so that this works correctly so i'm going
to follow this hyperlink and this takes me to
4948.08 -> the global security page of jenkins and if i
scroll down to the agents section i have to enable
4958.96 -> a tcp port for inbound agents
and i can select random or fixed
4965.52 -> and i'm going to select fixed and i'm going to
enter just you know a high value port number
4974.32 -> that i know is not being used
and then i'm going to select save
4981.44 -> now i'll select manage nodes in clouds
and i'll select the windows agent again
4986.96 -> and now you can see that it tells us
at the top we can connect to the agent
4994.16 -> using one of these ways and the first we can
run from the aging command line this command
5001.68 -> and this is the command that we're going to use
to run the agent program on this windows pc so
5007.44 -> i'm going to copy this command to my clipboard and
i'm going to download the agent.jar file locally
5018.24 -> and now that we have that downloaded
i'm going to open up a git bash session
5025.28 -> and i'll navigate to the directory
where the agent.jar file was downloaded
5032.08 -> and i'm going to paste the command
5036.56 -> into the session and we'll run it and
see if if the agent connects successfully
5047.36 -> okay and it looks like it did connect
it says that it's connected right there
5053.68 -> so i'll refresh the page and it says that
the agent is connected i'll navigate back
5059.68 -> to the dashboard we'll create a new item
and we'll call it test windows agent
5069.12 -> i'll select freestyle project and then i'll
select restrict where this project can be ran
5076.48 -> and i'll use the windows label this time
5085.6 -> and in the build section i'm going to add a single
5089.6 -> build step execute shell and we'll
say echo hello world to helloworld.txt
5101.12 -> and we'll select save and then
let's go ahead and build this job
5113.36 -> okay so i'll navigate into the the job console
output and you can see at the top of the console
5121.28 -> output it's building remotely on the windows agent
using the windows label and then it specifies
5127.92 -> the workspace that it's using on my local
windows pc and it looks like it was successful
5134.88 -> with the echo command as well we can quickly
verify that in git bash supply cd to downloads
5142.56 -> and then jenkins agent data i'll cd into the
workspace and then i have the job directory if
5152.96 -> i cd into the job directory we can see the hello
world text file did get created if i cat that
5163.36 -> the hello world is in that text file
5172.32 -> hey what's up everybody and welcome back to our
tutorial series on jenkins in the last video
5177.36 -> i showed you how to create a jenkins job for a
simple maven project and our jenkins server has no
5182.72 -> problem running this job or really any of the jobs
that we've created in the previous videos but in a
5188 -> corporate environment jenkins jobs might consume a
significant percentage of resources on the machine
5193.76 -> that's hosting the jenkins server especially
when there are many jobs ran in parallel
5198.64 -> so let's take a look at our next topic that will
help mitigate this challenge in this video we are
5203.6 -> going to configure jenkins controller and
jenkins agent nodes and before i walk you
5209.2 -> through the configuration steps i first want to
discuss the problem that we're trying to solve
5214.64 -> as software teams and their organizations
grow so does the need to scale jenkins
5220 -> in addition software teams may need to build and
test software on multiple platforms like windows
5226.08 -> macos and linux and a single jenkins instance
will likely be unable to meet these requirements
5232.32 -> in order to meet these requirements we must
scale jenkins up and or out jenkins can support
5238.8 -> organizational growth as well as the need
for multi-platform build and testing through
5243.04 -> the use of agents jenkins agents are machines
that the jenkins controller can delegate the
5248 -> task of building projects to in a distributed
manner an agent node might be a windows machine
5253.6 -> a linux machine or some other platform that
supports java this allows multi-platform build
5259.28 -> and testing using the same jenkins server and it
also allows us to scale our jenkins out as needed
5265.44 -> all we need to do is add additional agent nodes
if we take a look at the architecture shown here
5270.88 -> the jenkins controller node is the jenkins server
that we've already configured in previous videos
5276.4 -> we will be adding a linux agent node in this video
after we've configured our jenkins agents the
5281.76 -> jenkins controller will be able to schedule builds
on each of the jenkins agents according to the
5286.48 -> jenkins job configuration i'll briefly summarize
the environment that i will be using in this video
5292.4 -> the jenkins controller and one of the jenkins
agent nodes are hosted on azure one additional
5298.08 -> agent will be ran on my windows pc the jenkins
controller and jenkins agent nodes hosted in azure
5304 -> both have public ips additionally port 22 is open
for inbound traffic on the azure agent one thing
5310.64 -> i'd like to point out is that we won't be using
the azure vm agents or aws ec2 jenkins plugins
5317.44 -> these plugins allow you to dynamically provision
agents in the cloud you may be wondering why we
5322.64 -> aren't using these plugins and it's not because
they aren't useful these are very useful plugins
5327.44 -> but the method that i'm going to show should
be cloud agnostic and can be applied in an
5331.6 -> on-premise environment or without a cloud
account you could even set this up to run
5336.08 -> entirely on a single machine now that we've
covered those details let's get started
5343.2 -> so the first step to set up our jenkins
controller in jenkins agent nodes is to create
5348.48 -> an ssh key pair i have my terminal up already
i'm using git bash and in git bash i'm going to
5356.56 -> use the ssh key gen command to generate a new
key pair and i'll call it uh azure jenkins agent
5368.72 -> and i'll leave the passphrase empty
5371.92 -> okay so that generated a new key pair
and i'm going to cap the private key
5382.64 -> and i'm going to copy the
contents of the private key
5391.6 -> and then i'm going to navigate to jenkins and in
the jenkins controller i'm going to navigate to
5398.8 -> manage jenkins and then we'll
navigate to manage credentials
5407.04 -> we'll open up the jenkins credential store
and then global credentials and then i'm
5412.48 -> going to select add credentials and then the
kind of credential that we're going to use
5417.84 -> is ssh username with private key and we'll give
it an id we'll say it's azure jenkins agent and
5429.6 -> the username is going to be azure user and
then the private key will enter directly
5438 -> and i'll just paste the private key into
that field okay and then i'll select okay
5446.56 -> the next step is to copy our public key to the
machine that is going to be our jenkins agent
5452.32 -> hosted in azure and i already have an ssh session
open with that machine so i'm going to open up
5460.24 -> that session and i'm currently on the uh logged
on to the machine or the vm that will be running
5470.16 -> as a jenkins agent and i'm going to uh modify
the authorized the authorized keys file
5482.16 -> and add the public key that we just created
5487.68 -> okay
5493.28 -> so in the other terminal window
i'm going to cat the public key
5507.92 -> and i'll copy the public key value
5515.68 -> and i'll add this public key
to the authorized keys list
5523.12 -> and then we will save that file so now we should
be able to ssh or this jenkins instance should
5531.28 -> be able to ssh to this vm hosted in azure so we
can begin configuring this azure vm as a jenkins
5541.44 -> instance inside of our jenkins controller so i'm
going to navigate back to the jenkins dashboard
5549.84 -> and from here i'm going to
navigate to manage jenkins
5554.56 -> and then i'm going to select manage nodes and
clouds and as you can see from this list there's
5560.96 -> currently only one node configured for this
jenkins instance and it's the machine that this
5566.88 -> jenkins server is currently running on and
we're going to add two additional nodes
5571.76 -> the first node is going to be our azure vm and
to add an additional node i'm going to select
5578.96 -> the new node button here and i'm going to provide
a name for the node we'll call it azure agent
5590.08 -> and then i'm going to select that this is a
permanent agent and this is a permanent agent
5595.52 -> as opposed to an ephemeral agent which could
be dynamically provisioned and decommissioned
5601.68 -> and after selecting permanent agent i'm going
to click ok and it takes us to a configuration
5608.48 -> page where we can specify additional
configurations for this new jenkins agent
5616 -> and it includes a description as well as the
number of executors on the jake and jenkins agent
5623.44 -> so the same as we can control the number of
executors on the jenkins controller we can do
5628.08 -> so on the jenkins agent so that it can have
it can perform multiple builds in parallel
5635.84 -> i'm going to leave the number of executors
as one in this case the next configuration
5641.68 -> is the root directory and this is going to be
the directory that the jenkins agent caches all
5647.2 -> of its build data and this can be a pre-existing
directory or directory that's created on demand
5653.2 -> and in my case i'm going to create a directory on
demand and i'm going to call it jenkins agent data
5663.36 -> and this directory is going to be created under
the home directory of the azure user which is
5669.68 -> the user that jenkins is going to be using to
log into the azure vm the next configuration
5677.52 -> is very important it's called labels and labels
are a way of categorizing your jenkins agents so
5684.8 -> for instance you might have windows nodes and
linux nodes and it might be important to have
5690.88 -> certain jobs only run on the windows nodes
and other jobs run only on the linux nodes
5697.92 -> so for this agent i'm going to specify a linux
label since the azure vm is running a linux image
5707.76 -> the next configuration is the usage configuration
and we can specify whether to use this node as
5714.32 -> much as possible or only build jobs with label
expressions matching this node and that simply
5722.4 -> means that anytime a job specifies to build
on certain labels for instance the linux label
5729.68 -> then uh those builds could be scheduled on this
agent if it's online and we will use the label
5737.76 -> expressions but i'm going to leave it as the
first option use this node as much as possible
5744.16 -> the next configuration is the launch method
and the launch method is a really important
5749.12 -> configuration uh when you're setting up a new
jenkins agent and we have several options for
5755.68 -> launching a jenkins agent and the first option is
launching an agent by connecting it to the master
5762.08 -> and the master is the older verbiage and
now it's called the controller so this is
5768.88 -> launching an agent by connecting it to the
controller the jenkins controller and the second
5775.36 -> option is launching an agent via execution of a
command on the controller and then the last one
5780.88 -> is launch agents via ssh and for this particular
jenkins agent i'm going to use a third option
5787.92 -> launch agents via ssh and for the second
node which is going to be my windows pc
5795.2 -> i'm going to use the first option launch agent
by connecting it to the controller when we use
5801.52 -> the first option jenkins allows us to download
an agent jar file and that jar file is running
5808.56 -> the java application that is the jenkins agent so
we have to download the jar file to the jenkins
5815.28 -> agent and then run the java application inside of
that jar file which will establish a connection
5822 -> with the jenkins controller and with the second
method launch agent via execution of command
5828 -> on the controller uh this allows us to specify
a launch command in this field and the command
5834.64 -> if i expand the uh the help uh text here
the command can be very simple we could
5843.44 -> specify ssh and then we could ssh
onto the jenkins agent node and run
5850.48 -> the agent jar file directly or we could invoke
a script on the jenkins agent node in the event
5860.08 -> that we had we have to set up environment
variables on the agent node in order to
5866.96 -> run whatever builds that agent will be running
but in my case i won't be using that launch method
5873.6 -> i'm going to use the launch agents via ssh for
this first jenkins node and uh in the host field
5884.08 -> i'm going to specify the ip of the jenkins um
the jenkins agent node which is a an azure vm
5892.88 -> and i've already copied this vm's ip address so
i'm going to paste it into the host field and
5898.56 -> then for the credentials i'm going to select the
private key that we created earlier in the video
5905.36 -> for host key verification strategy i'm going
to select non-verifying verification strategy
5913.44 -> and then for availability i'm going to leave it as
default keep this agent online as much as possible
5920.48 -> we have a couple of other options that we can
use for availability like bring this agent online
5925.36 -> according to a schedule or bring this agent online
when in demand and take offline when idle so if i
5932.48 -> were to select that i could specify an in-demand
delay and essentially what this means is it's the
5941.52 -> number of minutes as it says here in the the help
section it's the number of minutes for which jobs
5946.72 -> must have been waiting in the queue before jenkins
will attempt to bring this agent online and then
5952.32 -> we can also specify an idle delay and this
is the number of minutes that the agent will
5958.4 -> remain idle before jenkins will take it offline
so this availability strategy might be useful
5964.96 -> if you're trying to optimize your costs on the
jenkins agent nodes but in my case i'm going to
5972.4 -> select the first option keep this agent online as
much as possible i'll leave the node properties
5978.88 -> unchecked and then i'll select save and now
you'll notice that the azure agent node has been
5987.2 -> added to our nodes list and under the build
executor status we not only see the controller
5994.8 -> node and its two executors but we can also see
the azure agent node and its single executor and
6003.36 -> if we take a look at the logs on this azure agent
we'll be able to see that the jenkins controller
6010.64 -> successfully made an ssh connection to the azure
vm and after it authenticated if we scroll down
6021.44 -> a little bit it copied the remoting.jar
and this remoting.jar is essentially the
6029.44 -> jenkins agent program that will run on that azure
vm and you'll also notice that it created the
6036.72 -> jenkins agent data directory since that didn't
exist on the on the vm and after it copied the
6043.92 -> jar file uh it cd into the jenkins
agent data directory and it started the
6052.16 -> the agent jar file and in the final
line of the console output here
6056.96 -> you can see that it specifies that the agent
successfully connected and is currently online so
6062.88 -> let's navigate back to the jenkins dashboard and
i'm going to create a very simple job and we'll
6069.84 -> call it test azure agent and this will be
a freestyle project i'm going to select ok
6083.84 -> and in this job i'm going to select
restrict where this project can be run
6088.64 -> and when i select that i get a field label
expression and this allows me to specify a
6095.04 -> label that was previously created uh like
a label that was created when we were
6099.28 -> configuring the jenkins agent for instance uh
and when i specify a label this job will only
6108.16 -> be ran on nodes that match those labels so for
the agent that we just created i created a linux
6116.72 -> label so as i start typing linux it autocompletes
it recognizes the label that i previously created
6124.32 -> and i'll backspace here and then it says
label linux matches onenote so anytime
6130.64 -> this job runs it should run only on our azure
agent node and now that we've specified that
6137.52 -> label i'm going to scroll down to the build
section i'm going to select add build step
6146.08 -> i'll select execute shell and i'll do something
really simple here i'll just echo hello world
6156.08 -> into a new text file
6163.04 -> and then i'll select save
6166.4 -> so now that we've created this job
let's go ahead and select build now
6174.64 -> and i'll go ahead and open up the first build
console output and then you can see at the top
6180.72 -> of the console output here it specifies that it's
building remotely on azure agent with the linux
6187.68 -> label and it's building in the following workspace
and it looks like the echo command did work
6194.08 -> uh correctly but let's just verify it uh by
logging into the vm and checking the workspace so
6203.12 -> if i take a look at the vm i have the jenkins
agent uh data directory so i'll cd into that
6213.44 -> and then i'll cd into the workspace and
i can see the job name test azure agent
6222.56 -> and i see uh helloworld.txt so if i cat
that and it does contain hello world
6229.44 -> inside of inside of that file so it looks like
our first jenkins agent is working correctly
6235.92 -> so that's pretty much all i had for this video
and in the next video we are going to discuss
6240.4 -> jenkins pipelines so i will
see you in the next video
6249.76 -> hey what's up everybody my name is moss and
welcome back to our tutorial series on jenkins
6254.56 -> until now we've only created
freestyle jobs and maven jobs
6258.4 -> in our jenkins server but in industry
you'll need more than a single freestyle job
6263.2 -> to facilitate your full build and release
process and for these more complex use
6268.24 -> cases jenkins allows you to define your
build and release process in groovy code
6275.92 -> in this video i'm going to introduce you to
jenkins pipelines let's begin with a brief
6281.92 -> overview as a team software development
process matures it can become difficult to
6287.44 -> model the build and release process using only
freestyle jobs in jenkins in order to mitigate
6293.36 -> the complexity of managing multiple freestyle
jobs the jenkins pipeline plugins allow you to
6298.64 -> model those complex build and release processes
as groovy code in what's called a jenkins file
6306.08 -> so what are some of the benefits of using a
jenkins pipeline if we check in the jenkins
6310.56 -> pipeline code contained within the jenkins file
into version control then we immediately get the
6315.84 -> benefit of traceability and control over changes
made to the pipeline the other benefit of version
6322.08 -> controlling the jenkins file is that the pipeline
exists independent of a jenkins server which
6327.92 -> means if for some reason the jenkins server was
accidentally destroyed the pipelines would not be
6333.04 -> destroyed since they're managed in a source code
management server the other benefit of jenkins
6337.68 -> pipelines is that they are highly extensible
through the use of shared libraries and plugins
6342.64 -> in addition pipelines support logical operators
such as conditionals loops and parallel execution
6349.52 -> let's also quickly discuss some key pipeline
terminology the first is the concept of a pipeline
6355.84 -> a pipeline is a user-defined model of a build
test and release process for a software product
6361.84 -> the second term you should be familiar with
is node a jenkins node is a machine that the
6367.28 -> jenkins controller can execute pipeline jobs on
the next concept that you should be familiar with
6372.4 -> is a stage a jenkins pipeline stage is a logical
grouping of steps that typically align with the
6378.24 -> build test and release portions of the software
development life cycle so for instance you might
6383.04 -> have a build stage a test stage and a deploy stage
you should also be familiar with the concept of
6390.4 -> steps steps are individual tasks completed within
a stage of a pipeline for instance a single step
6397.2 -> could invoke a jenkins node's shell and execute
a command like ls or make directory on it
6404 -> it's also worth mentioning the two types of
jenkins pipelines there are declarative and
6408.96 -> scripted pipelines declarative pipelines are a
newer feature of jenkins pipeline and declarative
6415.04 -> pipelines have richer syntactical features than
scripted pipelines which makes them easier to read
6420.96 -> and write now that we have a general understanding
of what jenkins pipelines are let's get started
6429.36 -> okay so i'm inside of my jenkins server
and the first thing that i want to do
6433.44 -> is install a new plug-in called the
pipeline maven integration plug-in
6438.56 -> now to write a jenkins pipeline you don't need
any additional plugins all of the plugins that
6444.08 -> you need to write a basic jenkins pipeline are
included when you install jenkins on a machine
6450.64 -> but if you have a maven project that you want to
build inside of a pipeline script it's good to
6455.76 -> install the pipeline maven integration plugin
because it adds some additional features to
6461.36 -> the pipeline and we are going to build a maven
project later on in the video so i'm going to
6467.2 -> go ahead and install that plugin and to do so
i need to navigate to the manage jenkins page
6476 -> and from manage jenkins i
want to select manage plugins
6480.88 -> and i'm going to select the available tab
and then i'm going to search for pipeline
6486 -> maven and this pulls up the pipeline maven
integration plugin so i'm going to go ahead
6492.16 -> and select that and i'm going to select
download now and install after restart
6502.32 -> and i selected the restart after it's been
restart automatically after it's been installed so
6509.52 -> jenkins is restarting and once it's restarted
we'll be able to utilize that plug-in
6519.28 -> so now that that plug-in has been installed let's
navigate back to the dashboard and we're going to
6524.32 -> create our first pipeline job so to create
a pipeline job i'm going to select new item
6532 -> and i'm just going to call it test pipeline job
6538 -> and then i'll select the pipeline
item here and i'm going to select ok
6545.76 -> now from here i'm going to go down to the
pipeline section and we can define a new pipeline
6553.44 -> in the pipeline section and we have this drop down
here and the first selection is pipeline script so
6558.88 -> we can define a pipeline script directly in this
job definition or we can define a pipeline script
6567.52 -> outside of jenkins and version control it in an
scm tool like github we will use this option in
6575.52 -> our second example but in the first example i'm
going to build the pipeline script directly in
6582.08 -> the job definition now it's possible to write
a pipeline script completely from scratch
6587.44 -> but if you're not too familiar with groovy or
pipeline syntax then it can be a little tedious to
6595.68 -> write a script by hand and what's convenient
about jenkins is it gives us this tool the
6601.92 -> pipeline syntax tool to automatically build um a
pipeline script so i'm going to go ahead and open
6608.08 -> up the pipeline syntax tool and this tool allows
us to automatically generate pipeline code and we
6616.24 -> have two options we have the snippet generator and
then we have the declarative directive generator
6622.4 -> with the snippet generator we can define
individual steps and remember that steps
6628.96 -> are individual tasks within a particular stage of
a pipeline and let's take a look at some of the
6635.44 -> steps that are available to us so the very first
step that we can do is we can archive artifacts
6642.08 -> we can build a job that exists on this jenkins
instance we can also echo we can use the echo
6649.6 -> command to print a particular message to the
console and then we can enter the message here
6656.8 -> okay and then when we uh enter the message or we
fill out whatever parameters are necessary for the
6664.48 -> step that we selected we can select generate
pipeline script and then this automatically
6670.4 -> generates the uh the command that we would enter
into the jenkins file so you would use the snippet
6678.08 -> generator for automatically creating individual
steps within a pipeline stage but if you want
6685.04 -> to define the overall structure and the stages
of the pipeline we would use the declarative
6691.04 -> directive generator instead so from here it
gives us a sample directive drop down list
6697.2 -> and in this drop down list we can select various
directives and the one that we're going to want
6704.16 -> to use is the stages directive so we want
to define multiple stages for our initial
6712.4 -> sample pipeline once we've selected the
stages directive i'm going to add a stage
6720.48 -> and the first stage that uh i'm going to
define is the build stage okay so this stage
6727.28 -> is going to be responsible for building
the code base whether it be you know a c
6732.96 -> plus code base or a java code base and the
build stage is going to contain steps so
6740.8 -> the build stage could contain parallel stages so
we could run other stages in parallel of the build
6747.04 -> stage sequential stages or a matrix but in this
case for a simple pipeline we're just going to
6756.56 -> have steps included in this stage and then after
specifying that steps are contained within this
6763.04 -> stage i can also specify additional options so for
instance i can specify that this stage should run
6770.56 -> on a particular subset of agents maybe linux
jenkins agents or windows jenkins agents
6778.16 -> and then i can also add when conditions to the
stage i can add post stage or build conditions
6785.68 -> i can add environment variables for this
particular stage so there's a lot of options
6791.04 -> that i can utilize in a stage but i'm going
to leave it as that and create a new stage
6798.56 -> and we'll call this the test stage and this will
also contain steps and then we'll create one
6806.96 -> last stage and we're going to call it the deploy
stage okay so the testing stage of course would be
6814.56 -> the stage where you would test the
code that was built in the prior stage
6819.36 -> and then in the deploy stage ideally if the
test passed this would likely be a conditional
6826.08 -> stage if the test passed in the testing stage
then you would deploy your changes to production
6833.04 -> or maybe if you had like a qa environment
or some sort of promotion process you would
6839.04 -> initiate that promotion process so these three
stages represent the skeleton of a new pipeline
6846.08 -> and to generate the uh the code for these stages
i'm going to select generate declarative directive
6853.76 -> and you can see here that it uh automatically
generates these stages okay so we have the build
6863.12 -> stage the test stage the deploy stage and then
within each stage we can have one or more steps
6871.52 -> so what i'm going to do is copy this generated
code into my editor and i'm going to begin a
6879.36 -> new jenkins file so i'm going to open up vs code
and before i paste this code in i need to define
6889.36 -> a pipeline block so i'm going to say pipeline
and then brackets and directly under the pipeline
6898.24 -> block i'm going to specify agent any and what this
um statement means is that this pipeline can run
6908.16 -> on any available jenkins agent and
then after the agent any statement
6914.8 -> i'm going to paste in the uh stages block as well
okay so now we have our stages defined within the
6923.52 -> pipeline block but right now this pipeline doesn't
have any steps defined within the stages so let's
6929.92 -> define a step within each of the stages so i'm
going to use the snippet generator in jenkins
6941.92 -> and let's use an echo statement so i'm going click
echo here and then let's just say hello world
6952.64 -> generate pipeline script and then let's
copy this into our new pipeline script
6959.68 -> right so i'm going to delete this comment here
6964.08 -> i'll paste in the echo statement
and here we'll say building
6975.6 -> and then for testing
6980.64 -> as you can imagine we'll say that we're testing
6987.28 -> and then same for here we'll
just say that uh we're deploying
6999.44 -> and then we'll add one more to
indicate that the pipeline is completed
7006.72 -> okay so this should be a valid
pipeline so let's go ahead and copy it
7012.48 -> and navigate back to our
our pipeline job definition
7019.44 -> and i'm going to select configure
and go back to the configuration page
7023.84 -> and then under the pipeline section
i'm going to paste the pipeline script
7029.6 -> into the uh into the field here okay
so let's go ahead and click apply
7037.12 -> click save and i'm going to go
ahead and build the pipeline
7047.52 -> and it looks like the build failed so let's
go ahead and open up the console output
7052.24 -> and i can see here that it looks like it
was expecting a closing bracket at line 23
7059.04 -> so let's navigate back to the
editor and okay it looks like i
7066.32 -> i missed uh the closing bracket for the
pipeline okay so let's move that in one
7077.2 -> alrighty and then let's go ahead and copy this
7082.32 -> updated uh script and then we're going to
configure again and then we'll paste it back in
7093.52 -> all right let's go ahead and
save and i'm going to build again
7106.96 -> okay and now the build is passing and in
addition to a passing build you'll notice that
7112.72 -> this stage view also uh popped up after the build
completed and the stage view uh basically gives us
7120.8 -> an overview of what happened in any particular
pipeline build and it separates it out by stage
7128.96 -> so we can see here the status of the build stage
the status of the test stage and the deploy stage
7135.44 -> we also can see the average stage stage
times which in this case there's only one run
7143.2 -> so it's the same as the actual the
the current execution of of this build
7148.32 -> so it didn't take long 391 milliseconds
these are pretty uh quick stages
7155.2 -> and for each stage we can see logs contained
within that stage and you can see our echo
7162 -> statement building in the build stage and same
for the test and deploy stages as well so you
7170.32 -> can access the logs uh through this interface but
you can also of course open up the console output
7176.8 -> and see roughly the same but maybe a
little bit more verbose so as you can see
7183.36 -> writing a basic jenkins pipeline script is pretty
straightforward but of course you want to build
7191.28 -> test and release code in a pipeline script and
in this example we didn't have any code that we
7199.04 -> built tested or released so let's go ahead and
create a new pipeline and we'll actually build
7206.24 -> a maven project in our new pipeline and we'll
also utilize the pipeline maven integration
7212.48 -> plugin and before we create the new pipeline job
i want to real quickly show you the um the github
7220.08 -> repository that we're going to build and it's
this one the sample maven project and it's a
7226.56 -> very uh basic java application that just prints
hello world to the console and it has a single
7235.36 -> test class using junit and in the
single test within that test class
7242.48 -> it just uh runs an assert true on a condition
true so the test should pass and this is the
7248.88 -> same project uh that i used in earlier videos
when we were discussing maven jobs in jenkins
7257.28 -> so what we're going to do in this repository is
create a new file and it's going to be a jenkins
7262.64 -> file that contains our pipeline code and we'll
keep it at the root directory of the project
7268.48 -> so i'm going to select add file create new file
and then we're going to call it jenkinsfile
7275.12 -> with no extension just plain like that and
then we will define the pipeline block here
7287.04 -> and agent any statement okay
and then we're going to generate
7294.48 -> automatically generate the rest of the
pipeline so let's navigate back to jenkins
7299.76 -> and we'll create a new pipeline job so
i'm going to navigate to the dashboard
7307.04 -> and from here we'll select
new item and we'll call it
7310.88 -> test maven pipeline and then i'll
select a pipeline and then select ok
7321.28 -> and from here we'll scroll down to the pipeline
section and for the pipeline definition instead
7327.76 -> of defining the pipeline script directly in this
field we'll pull the pipeline script from scm so
7335.04 -> i'm going to select pipeline script from sem
and then for the sem system we'll select git
7342.72 -> and then we're going to specify this repository's
url so i'm going to select open a new tab
7351.68 -> and i'll copy the ssh url of this repository
7357.52 -> and we'll paste that in and it gives me
an error code since i haven't selected uh
7365.76 -> credentials so i'm gonna go ahead and select
uh an ssh key pair that i previously created
7372.96 -> okay so it looks like it uh authenticated uh
correctly and then under branches to build
7380.96 -> i only have the main branch so i'm going to update
the branch specifier and then under script path
7390.08 -> we have to specify where the jenkins file is
located in the repository since we're keeping it
7397.44 -> along with the code base and in our case we
have the jenkins file at the root directory
7404.4 -> of the repository so we can leave this as is but
if we had the jenkins file in a subdirectory we
7411.52 -> would have to specify that path in this field and
now we're going to define the actual pipeline and
7417.92 -> i'm going to use the pipeline syntax tool and i'm
going to select a declarative directive generator
7426.16 -> and i'll select stages so i get a stages block and
then i'm going to add a new stage and we'll call
7435.2 -> it maven install since within this stage we're
going to invoke maven and we're going to run the
7441.68 -> maven install command on our maven project so this
stage will contain steps and this is going to be
7450.88 -> the only stage that we really need since maven
install is going to you know complete the full
7459.52 -> life cycle so i'm going to select
generate declarative directive
7464.24 -> and then we get our stages block i'm going
to go ahead and copy this text i'm going
7471.44 -> to navigate back to our jenkins file in
github and we will paste the stages block
7480.96 -> within
7483.52 -> and let's navigate back to jenkins and
i'm going to scroll up to the snippet
7489.92 -> generator and we'll define a new step and this is
where the pipeline maven plug-in comes in so i can
7500.56 -> utilize a step called with maven okay and
then with maven provides a lot of options so
7510.16 -> with a specific maven environment i can perform
maven operations so i can specify a particular
7517.52 -> installation of maven or of the jdk i can
specify uh maven settings as well so there's
7527.6 -> a lot of options that the pipeline maven plugin
provides for this use case i'm going to use
7535.36 -> essentially all of the default selections and i'm
going to scroll down to generate pipeline script
7543.68 -> and generates a very simple with maven
block and i'll go ahead and copy that
7552 -> and then i'll navigate back to the jenkins file
7555.28 -> i'm gonna paste that into uh
the steps section okay and
7564.24 -> in the with maven block i'm going to
invoke the sh utility and then i'm going to
7574.4 -> invoke maven so i'll say maven clean install
all right and that should uh run maven
7585.2 -> perform a clean and then perform the install
lifecycle and this should be all we need since
7590.16 -> the jenkins file is stored with the code base
itself if the jenkins file was stored in a
7596.4 -> different uh code base than the maven project then
as an additional step we would also have to invoke
7603.68 -> git here to ins uh to clone down the uh the
code base but in our case since the jenkins file
7611.44 -> is uh in the same repository as a code base we
can leave it as uh as is and this is going to run
7618.24 -> maven clean install on on our java
application so i'm going to go ahead and
7625.92 -> commit this
7631.28 -> and let's go ahead and navigate back to
our pipeline and i'm going to select save
7638.88 -> and then let's select build now
7645.12 -> okay it looks like the maven install stage
failed and i get a message here that says
7652.16 -> maven not found so i think that the maven
installation might not be selected so i'm going to
7664 -> select configure and let's
open up the pipeline syntax
7670.88 -> i'll select with maven again and then with
the maven installation drop down i'm going to
7678.72 -> take a look and see okay so i should
have selected maven 3 i have a
7686.48 -> a maven installation that i can specify so
i think i was supposed to select this uh
7692.24 -> so let me generate the pipeline script and
as you can see when with maven is invoked
7698.72 -> now uh the maven installation is specified as a
parameter so i'm going to go ahead and copy this
7705.76 -> and i'll add it to our jenkins file okay
7715.28 -> and then let's go ahead and
7719.68 -> commit those changes
7723.84 -> alrighty then i'll navigate back to our pipeline
7733.28 -> and i'm going to select build now
7741.44 -> okay and it looks like the maven
install is working correctly
7746.16 -> okay so uh just to kind of recap what
i did i specified the maven insulation
7752.88 -> that the pipeline should use
when we invoked the with maven
7759.76 -> code block and if i take a look at manage jenkins
and i look at the global tool configuration
7768.48 -> under the maven section in maven installations
i have a maven installation that i install
7776.08 -> automatically called maven 3 okay so this is
what was showing up in the drop down menu in
7783.36 -> the snippet generator so i'll navigate back to our
pipeline and as you can see when the pipeline runs
7793.92 -> successfully the maven installation command
ran and let's take a look at the output here
7801.92 -> so the full life cycle the full install life
cycle ran so it built the sample java application
7811.6 -> it ran the single test and we can see
that the test ran here with zero failures
7819.12 -> and then we get successful artifact publishing
to the local repository the local repository
7827.36 -> in this case is just the jenkins workspace so
if i take a look back at the the job home page
7834.4 -> you can see the last successful artifacts are the
snapshot jar and the snapshot palm files that are
7842.8 -> contained within side of the workspace of build
2 so these are the build artifacts of build 2.
7849.2 -> and from the build page we can also evaluate
the test results of the pipeline in this case
7855.12 -> there weren't any failures and there was only
a single test case that was ran and it passed
7863.76 -> if i take a look at the home page we
also get the junit the test graph with
7870.64 -> the results of each builds test so as you can see
when we use the pipeline maven integration plugin
7877.92 -> it makes writing a pipeline script for a maven
project a lot simpler because all we need to
7885.2 -> do is specify that with maven block
and then we can pass in parameters
7889.92 -> to the environment the maven environment that
is generated by the pipeline maven plugin
7897.6 -> okay so we were able to specify an insulation as
a parameter to the with maven block and we could
7906.88 -> run other installations of maven as well if our
maven project was dependent on an older version of
7912.88 -> older or newer version of maven so that's pretty
much all i had for this video i hope you enjoyed
7919.04 -> it and in the next video we're going to continue
our tutorial on jenkins pipelines and if you'd
7924.4 -> like to read about jenkins pipelines be sure to
check out lambda tests learning hub for jenkins
7930.32 -> the learning hub has a lot of great resources
related to jenkins and real quickly i'll uh
7935.76 -> navigate to the learning hub and show you so
it's lambdatest.com forward slash learning hub
7945.36 -> forward slash jenkins and uh you have these
chapters which are separate articles on
7954.08 -> various topics related to jenkins and if you
were particularly interested in reading about
7958.56 -> jenkins pipelines you could check out the
creating your first jenkins pipeline article
7964.32 -> but again thanks for watching and
i will see you in the next video
7974.32 -> hey what's up everybody my name is moss and
welcome back to our tutorial series on jenkins
7979.44 -> in the last video i introduce you to jenkins
pipelines which are a key feature of jenkins
7984.56 -> and now we're going to take the
knowledge that we've learned over
7986.88 -> the previous videos and put
it to use for the next topic
7992.24 -> in this video i'll show you how to do cross
browser testing with the lambda test jenkins
7996.72 -> plugin before we get started i'd like to quickly
go over the prerequisites the first is that you'll
8004 -> need a lambda test account secondly you'll
need python 3 installed on the jenkins server
8010.48 -> and finally you'll also need to install
the python selenium webdriver module
8016.72 -> i'd also like to give a quick overview
of the lambdatest jenkins plugin
8020.8 -> the lambdatest plugin adds additional features
to jenkins jobs such as embedding test results
8026.4 -> in the jenkins build you can also configure your
lambda test credentials for your jenkins jobs
8032 -> and the tunnel also provides automatic
setup of the lambda test tunnel binary file
8036.96 -> which is required if you intend
on testing locally hosted sites
8041.12 -> now that we have a high level understanding of
the lambda test jenkins plug-in let's get started
8048.64 -> okay so the first thing that i want to do is walk
you through the code base that we're going to be
8053.36 -> testing in jenkins and i'm currently
inside the github repository
8057.92 -> and the repo is called sample to do app and
this is basically a very simple web application
8064.96 -> and it only has the index.html file here and
the the web application is actually hosted
8073.2 -> using a feature of github called github pages
so if you're not familiar with github pages it
8079.44 -> basically allows you to use github to host a web
page from a github repository and to navigate to
8088.64 -> the the page where this code base is hosted
i can navigate to settings in the repository
8096.64 -> and if i scroll down to the pages section and
select pages under the github pages section
8103.04 -> you'll see your site is published at this url so
if i go ahead and open up this url i should see
8110.4 -> my application and it's the lambda test sample
application and it's just a to-do list with
8117.6 -> a few items already filled out but if i wanted to
add additional items to the to-do list i can just
8124.64 -> fill it out here and then select add and i can
also mark items as completed using the check boxes
8131.6 -> as well now in order to test this web application
i've written a very simple python selenium script
8139.2 -> and if we navigate back to the code base we can
take a look at that script it's called test sample
8146.64 -> to do app.pi so i'm going to go ahead and open
it up and we'll quickly walk through this code
8153.52 -> and the first thing that we do after importing
our modules is define the url for our remote
8160.4 -> web driver and we get the url from an environment
variable that's predefined called lthub url which
8168.4 -> is short for the lambdatest hub url and we'll get
the value of this url in a little bit and after
8176.72 -> we define the url we then define the desired
capabilities using a dictionary and the first
8185.12 -> capability dictionary key value pair here
is the build name and we actually retrieve
8192.319 -> the build name from an environment variable that
is used by the lambda test plugin or rather it's
8199.439 -> defined by the lambda test plugin so this is
the lambda test build name environment variable
8206.479 -> and also notice that we set tunnel to be true
because we're using we are going to use the
8212.479 -> lambda test tunnel binary file and the lambda
test tunnel opens a connection from my computer to
8219.84 -> the lambda test platform and it allows the lambda
test platform to connect to a locally hosted site
8226.319 -> on my computer so after we specify the desired
capabilities we then instantiate a remote driver
8233.92 -> using the desired capabilities as well as the
url which is the lambda test hub url and after we
8241.76 -> instantiate the driver we can then make a request
to localhost and here we're making a request to
8247.68 -> localhost on port 8081 which is where we're going
to run our sample to do app when when it's running
8257.359 -> inside of a jenkins job after we connect to
localhost the driver finds an element by name
8263.68 -> line item 3 and it clicks that line item so
it should select the third item checkbox here
8272.72 -> and after it selects that checkbox we
then get a reference to the text box
8279.68 -> directly below so we'll get a reference to
this field here and then we send the keys
8286.16 -> testing in that field and then we select the
add button so we should get something like
8293.04 -> this right and i'll add that to the to-do list and
then we assert that no results found is not in the
8302.88 -> page source and directly after that we use a
very useful command here we execute script and
8311.04 -> then lambda test status equals passed and this
will actually update the status of the tests
8318.08 -> inside of the lambda test dashboard to pass
so this is a very useful uh script here
8325.04 -> and then directly after that we uh quit the
driver okay so now that we've walked through the
8331.84 -> code base and the test script uh let's navigate to
jenkins and we're going to install the lambda test
8337.92 -> jenkins plug-in on our jenkins instance so
i'll open up jenkins here and then from jenkins
8345.28 -> i'm going to select manage jenkins and
then i'm going to go to manage plugins
8355.6 -> i'll select the available tab then i'm
going to select i'll type in lambda test
8364.8 -> and the first plugin listed here lambda test
automation is the plugin that we want to install
8370.24 -> so i'm going to go ahead and check it and then
select download now and install after restart
8376.8 -> okay so it's pending and then i'll
just check the box restart jenkins
8388.479 -> okay so the plugin should be installed and now
i'm going to add uh my lambda test credentials
8395.359 -> to jenkins so i'm going to select manage jenkins
and i'm going to scroll down to manage credentials
8405.04 -> and i'll select the global credentials
and i'm going to select add credentials
8415.28 -> and from here the lambda test plugin added
a new kind of credential so if i open this
8423.359 -> drop down here you'll see lambda test credentials
8427.2 -> and i'll leave the scope as global and then the
username my username is techwithmoss gmail.com
8436.64 -> and then the access token i can retrieve from my
lambda test profile so if i navigate to lambda
8444.479 -> lambda test and then i can very quickly
uh access the uh the key if i just select
8453.359 -> configure tunnel here and then the key is the
the option here the key option right here so
8463.28 -> this value is the key that i would need to copy
into jenkins so i'm going to go ahead and do that
8471.359 -> and i'll go ahead and paste that in
8474.88 -> and we'll call it lambda test credentials
8481.12 -> and then if i select verify credentials
8484.64 -> it says successful authentication okay so let's
go ahead and select ok and add those credentials
8492.96 -> now remember that our test script references an
environment variable called lthub url which is the
8500.72 -> lambda test hub url and this environment variable
still needs to be set so let's go ahead and
8508.399 -> set that environment variable in jenkins
so if i navigate back to the dashboard
8513.359 -> and then manage jenkins and then
scroll down and select configure system
8520.96 -> i'm going to scroll down to global properties
and i have environment variables checked and
8527.439 -> i'll select add okay and we're going
to call it lt hub url just like it
8535.2 -> how it's referenced inside of the python script
and to get the value of the hub url i'm going
8542 -> to navigate back to lambda test and in my lambda
test account i'm going to select configure tunnel
8550.399 -> and down here where it says more details
here this is a link to documentation and
8556.88 -> in the uh documentation pages we have
a link to the capability generator
8563.52 -> okay if i select the capability generator it takes
me to a tool where i can automatically generate
8571.84 -> desired capabilities this also automatically
generates the hub url that's unique
8579.52 -> to my account and if i expand username and
access keys you'll notice down here hub
8587.439 -> this is my hub url so if i copy that to the
clipboard and then navigate back to jenkins
8595.84 -> i'll paste that into the value field and that's
going to be my hub url which my python script
8601.6 -> is referencing and now that we've saved
that variable i'm going to select save
8607.76 -> and we're going to create a new jenkins
job so i'm going to select new item
8612.8 -> and i'm going to call it lambda test job
8617.6 -> and it will be a freestyle project so i'm going
to select freestyle project and then select ok
8626.16 -> and the first thing that i want to do is configure
source code management so i'm going to select git
8631.84 -> and then i'm going to navigate back to github and
i'm going to retrieve the repo url so remember
8641.04 -> that it's ssh so i'm going to copy the ssh url and
then back in jenkins i'm going to paste that url
8649.76 -> in and i'm going to select credentials
that i previously configured okay
8657.439 -> and the branch specifier just have the main branch
okay and after we've set up source code management
8667.439 -> i'm going to scroll down to the build
environment and you'll notice that we
8672.08 -> now have a new option here called lambda tests
so i'm going to go ahead and select lambda test
8679.04 -> and this section is our interface
with the lambda test jenkins plugin
8684.16 -> if i take a look at the selenium test section
i can actually add selenium test capabilities
8691.359 -> directly in this interface so if i click add
here i can select an operating system browser
8701.439 -> a version and the screen resolution
as well and then i can add
8706.399 -> as many test capabilities as i need here
the one caveat with using this interface
8714.399 -> to define the capabilities is that we
have to reference an environment variable
8722 -> that is created by the lambda test jenkins plugin
inside of our python script and to find the name
8729.04 -> of that environment variable that the plugin
creates i'm going to navigate back to the
8734 -> capabilities generator and i'm going to navigate
back to uh well actually i'm going to navigate
8740.88 -> back to the documentation here and if i scroll
down to the section lambda test integrations
8748.88 -> and then integrations with ci cd tools
whoops i'll select the jenkins plugin
8758.16 -> and in the jenkins plugin page if i scroll down
8765.68 -> to the environment variable for
lambda test jenkins plug-in section
8770.96 -> it gives me a list of environment variables that
the the lambda test plug-in will use one of those
8781.04 -> variables is called lt underscore browsers
and this is an array of of combinations of
8788.319 -> desired capabilities so you can see here when that
environment variable is printed out to the screen
8795.359 -> it prints out the desired capabilities and
these are the capabilities that are defined
8800.88 -> within the jenkins job here okay but in
order to use these capabilities we have to
8809.359 -> reference uh when we're defining the
capabilities variable in the python script
8815.76 -> we would reference this environment variable
now i'm not going to do that here i'm going to
8820.96 -> use the desired capabilities as they are
inside of the python script but it's good
8826.24 -> to know that if you do want to utilize this
feature in the interface you can utilize
8832.319 -> that environment variable in your script to
do so so i'm going to remove this capability
8840.16 -> and the next configuration is use local tunnel
and the local tunnel or the lambda tunnel binary
8847.68 -> file is a feature that allows you to test your
private server urls or locally hosted web apps
8854.96 -> using the lambda test cloud servers and
since our web application will be hosted
8860.479 -> locally on this jenkins server when we're
running this job we will need to utilize
8866.319 -> the the lambda tunnel so i'm going to go ahead and
check that box and then in the next field we have
8874.56 -> the tunnel name which we can leave blank and it
will have a it will be given a default name and
8881.6 -> we won't make this a shared tunnel and we're also
not going to use the legacy lambda test tunnel
8889.28 -> but under optional tunnel commands we are
going to utilize one additional option
8896.479 -> when the plugin starts the lambda test tunnel
and that additional option is dash dash info
8907.84 -> api port and then the port that this will
run on so what this option will do is it will
8919.6 -> provide an end point the the lambda test tunnel
will publish an endpoint on port 8000 that we can
8926.64 -> can connect to and we can perform operations on
the tunnel for instance we can close the tunnel
8935.28 -> if we want to or we can get status the current
status of the tunnel as well we can also specify
8941.68 -> a download path for the tunnel but i'm going
to leave this blank and then i'm going to check
8948.56 -> use workspace path to download the tunnel uh into
okay and then for the lambda test credentials we
8957.68 -> already created those credentials so i'm going
to select them here and then for the last step
8966 -> as a post build action we want the test results
embedded so from the post build actions drop down
8977.52 -> you'll notice a lambda test report i'm going to
go ahead and select that and this action will
8983.52 -> generate a lambda test report inside of the
jenkins build and it uses the build name from
8990.16 -> the environment variable lt build name which
is created by the lambda test plugin so if you
8996.479 -> remember in the python script if i navigate back
to the code base and i open up the python script
9006.64 -> uh where the capabilities are defined in the first
key value pair i set the build key to the value of
9015.68 -> the environment variable lt build name okay so it
pulls the value of the lt build name and that's
9024.479 -> how we get the test report generated inside of
the jenkins build so i'll navigate back to jenkins
9033.12 -> and we're going to add a build step
and we're going to execute shell
9040 -> and we're going to add a few commands here to
start a simple python server that's basically
9046.08 -> serving the current directory the directory of the
workspace then we'll also shut down that server
9054.96 -> after invoking the python script and we'll also
shut down the lambda test tunnel using that info
9065.84 -> info api port endpoint so the first thing that i'm
going to do is invoke the sleep command and i'm
9075.92 -> gonna sleep for five seconds that just gives the
tunnel a little bit of time to make a connection
9083.52 -> and then after invoking sleep i'm going to
start the python server so i'm going to invoke
9090.72 -> python3 and then the module http.server
and we're going to run it on 8081
9100.88 -> since this jenkins server is running on 8080 and
then ampersand so that this is a non-blocking
9110.479 -> shell command it'll just execute this process in
the background and then we'll invoke python again
9118.8 -> and this time we'll run our python script so i'm
going to say test sample to do app dot pi and
9129.439 -> once we've once that script has completed
we'll be able to stop the http server that's
9141.359 -> serving this particular workspace and to do
that i'm going to use p kill so uh p kill
9148.479 -> and then dash f and uh this is kind of like
a fuzzy match for the name of the process
9157.12 -> and we'll put in quotes http server
so that should kill the python server
9163.76 -> after killing the server i'll invoke sleep
again and sleep for 10 seconds before
9170.319 -> uh shutting down the lambda test tunnel and
to shut down the lambda test tunnel i can
9178.16 -> curl and end point the info api port endpoint
with uh the delete method and then localhost
9194.8 -> 8000 and then the endpoint is api 0.0 and then
stop okay so this endpoint should uh shut down
9206.64 -> the lambda test tunnel after the tests have
been completed and that should be all we need
9212.96 -> so i'm going to go ahead and save this job and
let's go ahead and build it and see what happens
9222.08 -> i'm going to open up the console output okay and
we can see that it's sleeping for five seconds
9229.04 -> it invoked the server as well as the test script
9238.64 -> and now it's killed the http
server and sleeping for 10 seconds
9246.479 -> and then we curled the stop endpoint and you
can see here that status equals success so
9253.04 -> it successfully stopped the the tunnel and
if we want to check the output of the tests
9262.24 -> we can do so by navigating to the lambda test
dashboard and from the dashboard if i navigate to
9271.2 -> the automation section i can see in the very
top of the list here jenkins lambda test job
9279.68 -> started a couple minutes ago and if i open that
up i can see that the test pass and i can even
9288.319 -> watch the output of the test so if
i open this up and maximize it you
9295.04 -> can see the tests run pretty quickly but you
can see what what the test did so right here
9302.56 -> it selects the third item and then it adds testing
as an additional item to the to-do list and then
9311.04 -> we quit the driver so it was a very quick
test and if i navigate back to jenkins
9318.399 -> i'll navigate to the build page you'll notice
at the bottom left section here the lambda test
9325.6 -> report if i click on that i get kind of
a high level overview of of the tests
9334.16 -> and i can navigate directly to the automation page
9339.76 -> lambda test by clicking these links
right so it takes me directly to
9345.439 -> the build here as well okay so that's how we
can utilize the lambda test jenkins plug-in
9352.56 -> inside of a freestyle jenkins job but we also
want to do this from a jenkins pipeline so the
9359.68 -> next thing that we're going to do is create a
jenkins pipeline uh and inside of that pipeline
9365.439 -> we're going to invoke the lambda test tunnel so
we can connect to the lambda test platform and
9373.359 -> run the tests from a jenkins pipeline so i'm
going to go ahead and navigate to the dashboard
9381.2 -> and we're going to select new item
and i'm going to call it lambda test
9389.68 -> pipeline and i'll select pipeline
type and i'm going to select ok
9397.76 -> and from the configuration page i'm going to
scroll down to the pipeline section and i'm going
9404.56 -> to select pipeline script from sem because we're
going to store the jenkins file along with the
9410.8 -> code base and then for scm i'm going to select get
and then let's copy the url of the code base again
9421.84 -> okay i'm going to paste that in
9426.8 -> and select my credentials okay and
then the branch is going to be main
9434.88 -> and we'll also leave the jenkins file in
the root directory of the repository so
9441.68 -> we'll leave the script path as it is now and
we'll go ahead and start building the pipeline
9448.399 -> i'm going to use the pipeline syntax
tool like we did in the previous videos
9455.76 -> okay and i'm going to open up the
declarative directive generator
9462.72 -> and we're going to generate some stages okay
so scroll down here to the stages directive
9471.12 -> and select that one and then let's go
ahead and add a stage and the first
9477.76 -> stage that i'm going to create is going to
be called setup and it will contain steps
9483.76 -> and then the second stage is going to be called
the test stage and this will also contain steps
9490.96 -> those are going to be the only two stages that
we create and i'll go ahead and select generate
9499.04 -> directive and i get the stages generated down
here i'm going to copy them to the clipboard
9509.6 -> and then i'm going to paste them into vs code
9514.08 -> and before we paste the stages i'll want to
define a pipeline block and i'll specify agent any
9524.479 -> and then after that we can go ahead and paste
the stages block into uh the pipeline block
9532.08 -> and in the setup stage we're going to run several
shell commands to download the lambda test
9540.08 -> tunnel binary file and then run the lambda
test tunnel so that we can make a connection
9545.52 -> and then execute our our tests so we
need to get the download url of the
9553.439 -> lambda test tunnel and i'm going to navigate
back to lambda test the lambda test documentation
9564.8 -> and from the lambda test documentation i'm
going to scroll down to uh or scroll to the
9572.319 -> testing locally hosted pages section
and if i select the first link here
9579.76 -> how to connect lambda test tunnel for
linux my jenkins server is running on
9586.479 -> linux so i'm going to select this link but of
course if your jenkins server is running on
9591.04 -> windows you would want to select
this link and i'm going to open up
9598.479 -> this page and if i scroll down i have a
link here to the lambda test tunnel binaries
9606.319 -> so i'm going to go ahead and copy that link
address and then i'm going to open vs code back up
9615.359 -> and we'll invoke the shell command
and i'm going to use wget to download
9622.88 -> the lambda test tunnel uh binary file and then
in the next shell command we're going to download
9630.319 -> a utility to unzip the lame to test
tunnel binary file so you only need
9638.16 -> to use this shell command on the first run of
the pipeline and then you can remove it for
9646.479 -> future runs but i'm going to go ahead and
apt-get install zip unzip and once that is
9657.279 -> installed i'm going to uh invoke it to unzip
the uh lambda test tunnel uh zip file okay
9671.279 -> dot zip and once we unzip the tunnel binary
file we can go ahead and invoke the program so
9679.279 -> i'll go ahead and do so and we have to pass in as
parameters the username the lambda test username
9686.88 -> and we're going to use environment
variables for the username and access key
9693.92 -> just to as a best practice so i'm going to call it
lt underscore username and then dash dash key for
9705.359 -> the key parameter and we'll also reference
this as an environment variable so this is
9712.88 -> going to be lt underscore access underscore key
and then we'll also give this tunnel a name so
9723.68 -> tunnel name is going to be jenkins dash tunnel and
finally we'll also set the parameter info api port
9736.399 -> running on port 8000 and one last thing
is we are going to run uh this program
9744.56 -> as a in the background so i'm going to add
ampersand and close off that shell command
9753.84 -> now these environment variables haven't been
created yet so we will need to create them so
9759.92 -> i'm going to do that now and i'll open jenkins
back up and if i navigate to the dashboard
9771.439 -> and i'll select manage jenkins
9779.279 -> and then i'll select configure system
9785.52 -> and if i scroll down to global properties
9789.84 -> again we can add additional environment
variables so i'll go ahead and select add here
9795.92 -> and the first one will be the lt underscore
username which is tech with moss gmail.com
9804.399 -> and then the second environment variable is
going to be the lambda test access key okay
9811.92 -> and uh this value we can pull from the lambda
tests test dashboard actually we can pull it
9817.2 -> from the um hub url so this is in the hub
url we pass in the username and access key
9826.64 -> in the url so i'm going to go ahead and copy
the access key here and i'll paste it in
9836.319 -> and then i'm going to go ahead and select save
9841.76 -> and then let's open vs code back up and
that's pretty much everything that we
9846.24 -> need for the setup stage in the test
stage we'll essentially copy the same
9852.319 -> steps that we took in the job that we
just created in the in the build section
9859.68 -> so i'm going to go ahead and delete
this comment here and i'll invoke
9867.6 -> i'll invoke the shell command and uh just
like we did in the previous jenkins job
9874 -> we'll go ahead and sleep for five seconds uh just
to allow the the uh tunnel to make a connection
9881.6 -> uh and then immediately after that we'll
invoke python and we'll run the workspace
9892.08 -> uh we'll serve the workspace on port 8081
and we'll do so as a background process and
9903.6 -> after that we'll invoke our our test script
so test sample to do app dot pi and once the
9915.76 -> test script completes we'll then kill the
server so i'm going to invoke sh and then p kill
9926.96 -> http dot server okay once we kill the
server we'll uh add a small sleep statement
9940.64 -> okay we'll just sleep for 10 seconds and then
9943.84 -> we'll curl the end point to stop the lambda
test tunnel okay so delete and then uh localhost
9961.76 -> or 8000 and then api v 1.0 and stop okay so this
should work or behave essentially the same way
9975.359 -> as the jenkins freestyle job that we previous
previously created now what you'll want to do
9982.319 -> from here is copy the pipeline script and then
in github create a new jenkins file in the root
9991.12 -> directory of the repository now i've already
created a jenkins file so i'll just go ahead and
9996.24 -> open it up and i'll select edit and i'll go
ahead and paste the pipeline script into the file
10010 -> okay i'll go ahead and commit those changes
10013.68 -> and then let's navigate back to the pipeline
configuration page and i'm going to click save
10022.479 -> and then let's see if this builds
successfully so i'm going to click
10026.16 -> build now and it looks like it failed pretty
quickly so let me go ahead and open up the
10031.76 -> console output uh and it looks like i was missing
uh an end quote there so i'm gonna open up github
10044.56 -> and let's close off that end quote
10055.68 -> okay and then let's go back to jenkins and we'll
build again and let's see if we have any errors
10065.439 -> all right so i'm going to go ahead
and open up the console output
10068.8 -> and let's take a look at what's going on
so it download downloaded the lambda test
10077.359 -> tunnel successfully and we can see that here
and then we also install the zip unzip package
10088.399 -> which in my case has already been installed
and then after that package has been installed
10095.76 -> we unzip the lamid test tunnel and once
we unzip the tunnel we then invoke it with
10103.92 -> the parameters that we had previously that we
set previously in the pipeline and we sleep for
10110 -> five seconds invoke the python server and then
we invoked the test script but it looks like
10118 -> it looks like it failed here so we should
probably take a look at why it failed so it
10124 -> says build name should be of type string so
let's take a look at why that didn't accept
10131.68 -> our build name so let's take
a look at the test script
10136.24 -> in the code base and see if we can
troubleshoot uh what's going on okay
10144.88 -> and it failed at line 18 but um i think i know
what the issue is here because the build name
10151.76 -> in the in the capabilities is still using the
environment variable lt build name which since
10157.84 -> we're uh using the pipeline job that environment
variable isn't defined so if i navigate back to
10168.56 -> the pipeline script we can actually define that
variable within the pipeline script so if i edit
10177.84 -> the pipeline script and then below agent any i'll
invoke the environment block and inside of the
10187.84 -> environment block i'll define lt underscore build
underscore name and then we'll say it's equal to
10197.52 -> the name of the pipeline job which is lambda test
10202.8 -> hyphen pipeline okay and then we'll
close off that environment block
10209.6 -> and let's see if that fixes the issue
10221.12 -> okay and i'll navigate back to uh
10224.56 -> jenkins and let's uh run the build again
and see if we can get it passing this time
10234.64 -> okay i'll go ahead and open
it up and let's navigate
10241.68 -> okay it looks like it's running
the test script successfully
10249.2 -> okay so the test script uh ran without any errors
and we killed the http server it's sleeping for 10
10258.08 -> seconds and then it should close the lambda test
tunnel which it looks like it did successfully
10265.04 -> and let's take a look at the test results in the
lambda test dashboard as well so i'll open up
10270.88 -> lambda tests and i'm inside of the automation tab
and then you can see at the top of the list here
10279.84 -> the lambda test hyphen pipeline which completed
so i'll go ahead and open this up and it says that
10286.24 -> the test pass and if i take a look at the video
as well you can see that the tests ran the same as
10295.279 -> they did in the freestyle job so those are the
two ways that you can integrate jenkins with the
10300.96 -> lambda test platform you can utilize the lambda
test jenkins plug-in within a freestyle jenkins
10307.6 -> job but you can also run the lambda test tunnel
within a jenkins pipeline job in the event that
10314.88 -> your release process uses a jenkins pipeline i
hope you enjoyed this video and the other videos
10321.6 -> in this series and thanks for watching if you'd
like to learn more be sure to follow our blog
10328.08 -> at lambdatest.com forward slash blog as well as
our lambda test community at community.lambda
10336.16 -> you can also earn resume worthy
lambda test selenium certifications
10339.84 -> at lambdatest.com forward slash certifications
10364.16 -> you
Source: https://www.youtube.com/watch?v=nCKxl7Q_20I