LongCut logo

Introduction to Jenkins, CI/CD, and DevOps for Beginners

By Valentin Despa

Summary

Topics Covered

  • Full Video

Full Transcript

do you want to learn how to create a modern cicd pipeline in Jenkins this Hands-On course will take you from the absolute Basics to being able to run a simple application in the cloud all this

while going through the stages of building testing and deploying no lengthy introduction useless examples or tedious Theory just practical actionable

steps but before you invest any more time in watching this course let me address three common questions is this course any good for absolute beginners what Jenkins pipeline are we going to

build and finally is Jenkins still relevant today first of all I've created this course for complete beginners I break down Jenkins cicd and Docker as if

you're hearing about them for the first time we will start from installing Jenkins and take small manageable steps toward the complete cicd pipeline

whether you're on Windows Mac OS or Linux you can follow along so what exactly are we building we'll create a simple website using no JS in our build

process but do not worry if you use Python Java php.net or any other technology the principles we cover will be universally applicable since I'll be

showing you how to run the pipeline using Docker containers you will also learn to configure and run unit test end to end test publish reports and deploy

using the cloud provider netlify but isn't Jenkins obsolete while Jenkin is no spring chicken it remains a critical tool in many organizations this

course will teach you modern devops practices including using Docker as a built environment and writing our pipeline as code with a Jenkins file these skills are transferable to any

cicd tool you may want to use in the future so you're definitely not wasting any time learning Jenkins and if any of this sounds unfamiliar don't worry I'll take you through this step by step I

typically don't speak so fast but way my name is Valentine and I'll will be guiding you through this course a PDF with a course notes and all the pipin scripts is available for download otherwise you won't be able to follow

along and with that being said I think we have everything we need to get started so let's go build some jenies pipelines Pria is a software developer

and works together with a small team at developing a web application every time the customer requests a change she has to rebuild the software test it and

upload it to a web server so that the customer can use the new version while priia loves writing code the entire process afterwards is repetitive and

quite honestly boring quite often mistakes happen and the application does not work as expected or is completely offline for a while priia raises this

problem in one of the team's Sprint retrospectives and Alex another team member suggests using a tool like like

Jenkins but what is Jenkins Jenkins is a free and open- Source automation server mainly used to automatically build and

test software to put this in more simple terms Jenkins is like a robot assistant that can automatically do specific tasks

on a computer particularly tasks related to building testing and deploying software Jenkins is like an assistant for software development

every time priia writes or updates a piece of software Jenkins can compile the software to ensure it is written correctly run tests to make sure

everything works as expected create a ready to use version of the software and deploy to a server and make it available for

users all this can happen without lifting a finger so while Priya is taking a short coffee break after completing work on a new feature Jenkins is working hard in the

background to get the new version released this process helps Pria and her team catch issues early ensures the software is always in a good State and

automates many manual tasks making the entire software development process more efficient and enjoyable in technical terms Jenkins is a continuous

integration and continuous deployment tool at its heart it's all about Automation and making repetitive tasks easier and more

consistent in this course we will look at how to use Jenkins to build a web application we will start from scratch by covering the absolute Basics and go

all the way up and figure how to deploy this app in the cloud throughout the course I'll also explain different Linux commands you need to know and also clarify the jargon you keep hearing like

devops cicd and knows what else so if you need to learn Jenkins because your team is already using it let's not waste any time and dig right into

it there are various ways of installing Jenkins if you already have Jenkins installed it may not be configured in a way that allows you to follow along with

this course I recommend using doer with this course so that all examples I am showing work exactly the same if you decide to install Jenkins in some other

way the examples presented may not work as expected and it will be very hard for me to help you troubleshoot the problems I try to make this installation process

as painless as possible so here's the plan in a nutshell first of all we're going to download Docker desktop because this allows you to run Docker on your

own computer and I prepared a repository which contains a Docker configuration which you can can easily start and once this configuration has been started and Jenkins is running we need to go inside

Jenkins and configure it and essentially start using it so let's go a bit into the details first you need to install Docker desktop on your computer there are installation packages for Windows

Mac OS and Linux if you check the resources folder you will notice that I've included detailed installation instructions as well as some troubleshooting tips yes it's no secret

for some of you getting Docker desktop to run can be a bit more challenging but generally should be an easy installation I also recommend creating a Docker

account this is how Docker desktop looks on my computer once Docker desktop is up and running we actually want to check if everything is working well so we're

going to use the following command Docker run and we're going to start an image which is called hello world going to write hello dasw world

so initially this image is not available locally so it needs to be downloaded and if you're seeing here this message hello from Docker it means that your Docker installation is perfect everything is up

and running the next step would be to download the configuration needed to start Jenkins using Docker I already prepared here a repository on GitHub and

depending on your skills you can use git to clone it or simply from here from code download the entire zip I'm going to take the option of cloning this

repository so I'm going to copy it and then go to a terminal and use git clone and then paste the address this will essentially copy this

entire git repository locally the name of the directory is install D Jenkins D Docker I'm going to use CD for change directory going to

type here a few letters and enter the directory install Jenkins Docker now inside this directory there are a few commands that we need to run and these

commands are also specified here so the First Command that we need to run is this one so this will build a Docker image containing Jenkins all you have to

do is copy this command hit enter and wait a few seconds until this image is being created you only need to do this once so don't worry doesn't matter so

much what we're doing right now once this image has been created and we don't see any errors we can jump then to step three I'm going to Simply start

Jenkins I'm going to use here contrl L to clear my terminal and paste the new command this is using Docker compose to start Jenkins first time we're running

these commands it does take a bit of time because Docker needs to download all these images but once they have been downloaded and are stored on your computer running these commands will be

be very very fast okay so what we will see here is that the containers have been started so if everything looks green you don't see any errors it means that everything is

fine and then finally to check if Jenkins is running we're going to go to Local Host on port 8080 so I'm going to click on this and simply use my browser to go to this page and there are a few

steps that we still need to do here in Jenkins we have now reached step number three where we need to do a few things so Jenkins has been started but it's currently not configured we need to

configure a few things it only takes a few minutes now the first thing that we need to do is to unlock Jenkins and this is like a security thing we only do this once during the installation and we're

given here some instructions and essentially in a file there is like an initial admin password that we need to grab now I'm not sure about your lanux scill so I'm going to try to make this

as easy as possible what we're going to do here is going to copy this path here and we're going to go here to Docker desktop now what you should see in Docker desktop here are at least two

things you're going to see here this container here with the image hello world this is what we executed the first time when we have installed Docker desktop just to check if everything is up and running we don't need this

anymore so we can simply go ahead and remove it from here and what we're actually seeing here is this install Jenkins Docker and this contains two images

essentially this image my Jenkins is like where Jenkins is running so if we're clicking on this uh we can directly interact with the container

that is running Jenkins so this container has some files here and it also contain some logs you'll see here on the logs somewhere there are

essentially the installation logs of Jenkins and we're getting here this password that we need for the initial setup so this is available here in the

Lo if for some reason you don't see this in the logs there's also different way of accessing this so another approach would be to go here to EXA this allows

us to write a command directly in the container so for example we can use the cat command which has absolutely nothing to do with cats to print the information there so cat and the PA that we have

copied and this gives us the exact same password let's go back to Jenkins and complete the installation process I'm going to paste here this password you don't need to worry about this password we don't need to save it or something

like that we're not going to need it in the next step we are being asked about customizing Jenkins now Jenkins essentially it's just a skeleton and

it's just a platform and what actually makes Jenkins Jenkins are a lot of plugins that are added to this platform so we're going to go here with install suggested plugins because these are like

kind of like plugins that we'll be needing all the time and we don't want to go afterwards and individually install different plugin and this will take a few minutes to download and

install you'll see here the progress just going to jump to the end of this installation process all right so the installation process of the plugins is now over and

now what we need to do is to create our username the username that we'll be using to login into Jenkins now we could Skip and continue as an admin and use

that ini password all the time I don't recommend doing that so I'm going to go ahead and create here a user and I'm going to also use here

password ideally use a secure password because you never know when you need this you don't need to provide your full name but this installation process here requires an email address so I'm just

going to use here Valentine at example.com Jenkins is not going to send us any email so don't worry this is all a look

gole installation so username a secure password and this email address so let's go ahead and click save and continue this is the address where

you'll be accessing Jenkins so this is automatically detected so if you want to make a bookmark in your browser that's fine or just keep in mind it's HTTP

column localhost colum 8080 which means that this is running locally on our computer on port 8080 it's actually running inside a Docker machine but it

is mapped locally on our computer on this port so this is why we can access this information anyway don't need to do anything here I just want you to briefly explain what is this local host and port

8080 going to go ahead and click save and finish and Jenkin is ready oh I hope that this was an acceptable process but let's go ahead and see how Jenkins looks

like so start using Jenkins so this is how Jenkins looks like when you are starting it for the first time now don't worry if it looks a bit different when you see it essentially the concept

should be pretty much the same sometimes you know the user interface does change a bit but I know you're smart people and you'll be able to put one in one together and understand where you can find things apart from this I also

wanted to show you a few other things that you may want to have so maybe you don't want to have Docker desktop running all the time so there's a possibility of shutting down Docker

desktop and I recommend first to stop the containers that are running now here in the documentation there's also a command for that so super important you need to be inside this directory that

you have cloned this directory contains this Docker compost file which is actually the entire setup process so we can go for example and use Docker compost down so I'm going to copy this

command here and what is going to do here is going to stop all the containers right so it's going to stop Jenkins if we're going back to Jenkins and trying to use it we're going to see here that

there's nothing running on this boort so now jenin has been shut down of course you can also go ahead and stop Docker desktop Al together there also the option to pause

it now if you're going here to Docker desktop you can see that currently there are no containers running you can also pause Docker desktop it's a bit hidden here right at

the bottom maybe we can zoom in on this to have a better look so there's like this pause button when you don't need Docker desktop running kind of like makes your computer a bit faster and

also if you don't want to use it you can just simply quit so you can turn it off now when you open it the next time Docker will not automatically start somehow so you need to manually start

the containers once again to do that all you have to do is use Docker compose up so I'm going to copy this command go back here in the

terminal and will take a few seconds but this is nothing compared to the installation process so everything is up and running so we're going to see

here our containers status running perfect so we can jump back into the browser go to Local Host Port 880 and

our Jenkins needs a few seconds to start but we're going to go back here to the login page so we at the login page you're going to be asked for your username and this would be my password

and I also recommend like keeping yourself signed in because it helps so this is how you can install Jenkins and for any troubleshooting tips check

the resources so let's go ahead and create our first job in Jenkins now essentially a job refers to a set of commands that we want to execute it's essentially the

task that we want to automate in Jenkins to create a job you can do it right here from the start page but this thing will only appear one and typically next time you want to

create a job you will have to go here from the menu to new item let's go ahead and click here on create a job and in Jen is there are different types of jobs

that we can create we are going to go ahead and create what is called a freestyle project I'm going to see in a second exactly what that means so this will be our

hello and I'm going to add also here freestyle so that we know that this is a freestyle job so after we have given this job a name and have selected the

type let's go ahead and click on okay a freestyle job is a job that can be configured through this user interface and here in Jenkin there are different kinds of options that you can configure

and you can essentially click yourself through creating this job essentially in essence a job is supposed to run a command so what we're going to do here we're going to either scroll down or use

the menu here on the left hand side to go to build build steps and we're going to go ahead and add a build step now what we want to do

here is we want to execute shell so a shell is essentially an interface where we can write commands I'm going to select here execute shell

and what is the command that we want to use so for example we can use the command Echo going to write here Echo and between quotes I'm going to write

here hello from Jenkins now what is echo in Linux and other uni systems Echo is a command that outputs

the text which we call a string so this thing here between codes this is what we call a string and this is being passed as an argument to Echo we typically use

echo in Shell scripts as a way to display a message or sometimes to display the value of a particular variable throughout the course we'll also learn other l commands that are

useful while working with Jenkins and doing devops now with this one let's go ahead and save this configuration and run this job to see what

happens so I'm going to go ahead and click here on Save and initially nothing will happen we can go here back to the dashboard and you will see here that the

initial screen has disappeared so now we are getting here on the main page list of jobs that we can execute so we're going to go here again to hello going

back to the job and in order to actually run the command that we have written to run this job we need to click here on build now so only when we click here on build

now Jenkins will actually start executing that command and because this is a very simple job the execution is almost instant so what we're going to see here is the next part which is build

history so in the build history we're going to have all the executions of this job like a history of all the jobs that have been executed and the job that appears here on top is the latest

execution so what we can do is click on this green check mark so I'm going to make it just a bit bigger so that you can see it if you click on this check mark essentially you're going to go to

the console output so what is the console output the console output is essentially where Jenkins writes everything that has happened so it's keeping notes of what it is doing during

the job and it's writing it here so it's telling us a few things but what we are actually interested in is here this part so this is our Command we have used the

command Echo to display this text and then one line below you can actually see the text that we have executed so this is in a natural the

most simple job that you can create in jenet this is the hello world job now apart from this way of creating this freestyle approach which you can

navigate here from the top so we can go back to the job itself and if you want to change something about it you can go to configure so there are many things here that can be configured in this job and I'm going to go over this

configuration for a specific reason so I'm going to go back to this and this time we're going to create a different kind of job and this kind of job is called

pipeline so every time we want to go back to the start page we need to click here on top on dashboard this is how you come back to this overview of all the

jobs that you have and going to go here and click on new item and I'm going to write here hello but this time I'm going to write here

pipeline the type of this job will be pipeline let's go ahead and click okay and this is where we configure this Pipeline and you're probably looking at this and you're still seeing a lot of

checkboxes and a lot of options and you're probably thinking like what's the difference the freestyle isn't it like the same thing well no there's a fundamental difference is there still a

few things that we can configure through the UI but essentially most of the configuration happens right here at the bottom where it says Pipeline and here

we can define a pipeline script this is the fundamental difference between a freestyle job and a pipeline script now let's go ahead and see how a pipeline

like this looks like so we're going to select here from the drop- down menu going to select here hello world and we already getting the structure of a very

simple pipeline so in this pipeline we have this syntax you can see here pipeline starts here and ends here then a pipeline has different stages and

everything is wrapped between this curly braces and we have here a stage hello and we are using Echo to display message

it's essentially pretty much the same thing as we did before with just writing that command but now we're using this pipeline syntax that's the main difference so I'm going to go ahead and

save this and run it with build now so we can go ahead and inspect the results of this and again we're going to

see here the message we have specified when using Echo so the output is pretty much the same thing but the approach we have taken is quite different now let's

go back and make another change so I'm going to click here on hello Pipeline and to go to configure if want to quickly go all the way to the pipeline configuration from the menu going to

select your pipeline and quite often when working with these pipelines we want to use shell commands so this Echo is sort of like in between it's not really a shell

command it's something that Jenkins provides but in order to write a shell command we will use sh and between codes then we can put our Command so for example example we can

put a command Echo hello from Jenkins so this will do pretty much the same thing but quite often we need sh to be able to run different Linux commands

so let's take a look and save this and build it once again so what you should see here in the build history is that now the build number is being incremented so now we

are at build number two so we can click on this green checkbox and go directly to the console output where we can see this message so you will see it works pretty much the same but quite often we're going to use

S here's another example and another Linux command so for example we can use the Linux command which is called who am I so who am I is another command which

tells us who the current user is I'm going to write here with SH who am I all in one word and you probably notice here at the bottom save and apply and you're

probably thinking like what's the difference between them I'm going to show you second so for example if we click here on apply this job configuration will be saved but we're

not leaving the screen so this is quite useful if you want to have for example the pipeline execution in one part in this case I have here two tabs open so in one of them I can simply go ahead and

build something and in the other one I can simply keep this window open and make modifications to the script let's take an angular look this is the third execution going to take a look at

another command that we have executed so here you will see here our Command who am I and the response is Jenkin so this is how we can execute this

request now why do we need this what exactly is a pipeline now pipeline as you have seen a bit in the configuration

is essentially a set of stages or you can also call them jobs so we only have one stage here but typically a pipeline has multiple stages now right now we

only have the simple stage but we're going to be adding multiple stages to this Pipeline and then it will start making more sense in this lecture I just

wanted to briefly cover how you can create a job in two different ways and in upcoming lectures we're going to explore more how this works and why we

do it in a specific way so don't worry right now if things are a bit weird just try to understand how to create these jobs get them to run take a look at the logs and for the moment you're all

good so I have mentioned devops quite a few times and by now you have heard of devops as well so what is devops let me

tell you first what devops is not devops is not a standard or a specification different organizations may have a different understanding of devops

devops is not a tool or a particular software nor is it something you do if you use a particular tool or a set of

tools devops is a cultural thing it represents a change in mindset let's take a look at the following example you have a customer

who wants a new feature a business person let's call them a project manager would try to understand what the customer wants write some specifications and hand them over to the

developers the developers will build this feature pass it on to the testers who would test it once ready the project manager would review the work and if all

looks good would ask the developers to pass the software package to the sist admins to deploy it as you can see there's a lot of passing stuff around

and in the end if something goes wrong and often things go wrong in such situations everyone is unhappy and everyone else is to blame so why does it

happen because every group has a different perspective on the work there is no real collaboration and understanding between these groups let's zoom in on the relation

between the developers and the CIS admins the developers are responsible for building software ensuring that all these cool features that the customers

want make it into the product the it operations team is responsible for building and maintaining the it infrastructure ensuring the it systems

run smoothly securely and with as little downtime as possible do these groups have something in common yes of course

the software the product the problem is the it operation team knows very little about the software they need to operate and the developers know very little

about the infrastructure where the software is running so that devops is a set of practices that tries to address this problem but to say that devops is just a combination of development and

operation would be an understatement actually everyone mentioned before works on the software just in a different capacity since the

final outcome impacts everyone it makes sense for all these groups to collaborate the cultural shift that devops brings is also tightly connected

to the AGL movement in an ever more complex environment where business conditions and requirements change all the time and where we need to juggle

tons of tools and Technologies every day the best culture is not one of blaming and finger pointing but one of experimentation and learning from past

mistakes so we want to have everyone collaborate instead of working in silos and stages instead of finger pointing everyone takes responsibility for the

final outcome if the final product works and the customers or users of the product are happy everyone wins the

customers the project managers the developers the testers the CIS admins and anyone else I did not mention everyone wins however devops is more

than just culture to succeed organizations adopting devops also focus on automating their tasks manual and repetitive work is a productivity killer

and this is what we're going to address in this course automatically building and deploying software which falls under a practice called

cicd we want to automate as much as possible to save time and give us the chance to put that time to good use instead of manually repeating the same

tasks over and over again but to automate things we need to get good at using the Shell working with tools reading documentation writing scripts

quite often you may see devops being represented by this image while this does not give a complete picture of what devops really is it does show a series

of steps a typical software product goes through from planning all the way to operating and monitoring the most important thing I want you to notice in this

representation is that this process never stops it goes on and on in an endless loop this means that we continue going through these steps with each

iteration or new version of the software what is not represented here is the feedback that goes back into the product devops goes hand in hand with the alile

movement if alile and scram are new to you make sure to add this to your to-do list nowadays many organizations go through an agile transformation and

value individuals who know what agile and scrum are regardless of their role I've added some resources you may want to look into in the course notes if you

have some free time while commuting or doing other things around your house I highly recommend you listen to the Phoenix project as an audiobook it is an

accurate description of what companies that are not adopting devops go on a day-to-day basis and realistically portrays such a transition this is by no

means a technical book and I'm sure it will be a fun Liston so devops is a set of practices that helps us build successful products

to do that we need a shift in thinking and new tools that support automation however I must warn you that you can use tools that have devops

written all over them and still not do devops so devops is so much more than just adopting a particular tool in this section we will start working on

a simple project we want to automate any of the manual steps required for integrating the changes of multiple developers and create a pipeline that

will build and test the software we are creating in other words we will do continuous integration CI continuous

integration is a practice and one of the first steps when doing devops usually we are not the only ones working on a project when we are doing continuous

integration we are integrating our code changes with a code other developers created it means that every time we make

changes to the code that code is being tested and integrated with the work that someone else did it is called continuous

integration because we integrate work Contin L as it happens we don't want to wait for anything to do that for example we don't want to integrate work once per

week or once per month as it can already be too late or too costly to resolve some issues we typically integrate our

work multiple times per day even multiple times per hour the more we wait the higher the chances we will run into integration

issues one of the tools that en enable CI is a version control system like git which can keep track of all the changes if you never worked with Git before

check the resources folder for a quick introduction in this section we will use git together with Jenkins to verify any changes and integrate them into the

project now I'm going to be honest with you as we build more advanced pipelines you are more likely to encounter some issues so it is super important to pay

close attention to the explanations provided and if you encounter any errors just spend a bit of time trying to understand the error typically the error is trying to be helpful it's trying to

tell you what has happened we just need to do the effort trying to understand what you did and why that error is occurring also feel free to use the Q&A section to ask questions and

additionally in the section you will also find troubleshooting lectures so if something doesn't work check the troubleshooting lectures see if there's information there check the Q&A see if

there's anyone else who had the same issue as you and if not ask a question and I'll do my best to help you out finally let's do a quick recap when we

have multiple developers working against the same code repository CI is a practice that allows us to add and integrate our changes even multiple

times per day what comes out is a new version of the software product that we can deploy if you're still unsure about continuous integration at this point don't worry

that's absolutely normal we will Implement CI in our development process in the upcoming lessons and you will have a better understanding of it very

soon so far we have stored the pipeline configuration directly in Jenkins this is okay if you want to try something out and we don't want to go through the

entire process however if if we want to truly follow the pipeline as code principle we need to store this pipeline code in a code version system like git

which is probably the most popular solution to work with Git and use a git repository we will use a very popular

git hosting platform called GitHub so I'm here at github.com and here at GitHub you can create an account for free for the next next part of the

course you will need an account with github.com it is absolutely free to register for one we will use GitHub to store our project code

repository as well as the Jenkins pipeline file so go ahead sign up for an account follow all the steps and I will see you in the upcoming lecture after registering with GitHub

you should come to this page which is essentially the dashboard of GitHub this is where you have all the projectss and everything now honestly I can totally understand if you find this confusing

right now don't worry it will make sense in a second now in this section we're going to work on a project on an existing project which is actually quite common you rarely start the project from

the start so in the resources folder you will find the link to this public repository and this is a simple

application now we cannot all of us work on this application throughout the course so I will need each of you to create a copy of this project so that you can work on your own and practice

all the concepts that I'm teaching in this course now to Fork this project you first need to be logged in so if you're not logged in make sure that you log in and you should see here your icon on the

right hand side so now we are in a logged in stage to create a full copy of this project what we will do is we're

going to create a Fork so this is in GitHub terms the idea we are going to click here on this fork and essentially we're going to be asked how we want to

name our repository just simply go with the default and I also recommend leaving this flag on to copy only the main branch so let's go ahead and click

create for this will take a minute or two until all these files are being copied to your own identical copy of this Repository and you will see here that you are on

the right repository because it says here fored from this repository right so now we have a copy of the code this is where we typically start with a lot of

projects we need to get access to the code so that we understand what the application does so what does this application do now in order to work with this what we're going to do is we're

going to check out the code and open an ID which is an integrated development environment now if you already know how to work with Git You can simply go ahead

and clone this repository from here so you can simply use SS and clone it locally and use a tool such as Visual Studio code to do this now if you are

not so advanced in terms of git and working with his editors don't worry we're going to do everything in a browser as well so let me show you what I mean there's this option here in

gitlab which is essentially called code there's a tab called code spaces so what we can do here is to create a code space

on main main is the name of the branch main is the main development Branch development can happen in multiple branches and for this first part we're going to work on the main branch so this

is why we're going to create a code space on Main this takes a few seconds to set up but what you will get in a few seconds is a complete development

environment using a web version of Visual Studio code so this is how our code space looks like the first thing I like to do is to

go to settings and make some small changes now first of all we already know that light attracts bugs so let's go

ahead and select a darker theme okay much better apart from this I also like to enable what is called White spaces so

we're going to check in settings going to search for white space and when we have here the section render whitespace I'm going to select here all

I think this is it all right so what do we have here on the left hand side we have access to all our project files and we're going to get into them in a second

in this part this is where anything any file that we open will be displayed so for example I'm clicking here on this read me file I'm going to see here the

contents of this file just as well I can click here on package.json I can see the content we can also have multiple tabs open at the same time I think okay

anyway now here on the lower part of the screen we have the terminal so this is essentially the shell this is where we can type commands and when we're

developing something we typically have to type some commands to start a project now this is a nodejs project which uses a programming language called JavaScript

now it doesn't matter matter if you're using Java if you're using python or if you're using any other technology we're going to use this project simply as an

example to demonstrate some Concepts between the different Technologies and the different programming languages there are many similarities so what here will be solved

with one command it's going to be solved in a different framework and programming language with another command Now concept that almost all projects have is

the concept of depend so project relies on third party libraries essentially to do its work it has maybe third party Frameworks libraries that can help with

different things for a nodejs project all these dependencies are being stored here in this package.json or are being declared here in this package.json you

see here for example dependencies now we don't need to know exactly what all these dependencies are but as a first step we need to install these dependencies so let me make it just a

bit larger so that you can properly see what we're doing here so the way that we can install dependencies is by typing the command npm install and this will

take a minute or two for this dependencies to be installed but essentially without installing these dependencies we cannot go to the next step if you're seeing some warnings here

this is kind of like everyday situation when working with node npm is the node package manager so it's takes care of installing all these dependencies that

we need but if you don't seeing any errors here that's totally fine you can simply ignore what you see okay I'm going to press contrl L to clear the screen and the next step that we want to

do here is we want to get this project started right so imagine we are now developers we are new to the project and we want to see like what is this app all about how can we get locally something

working so the command that we need to run here inside this project directory is npm start let's see npm start type it and run it and this

essentially will create a development version of our application and typically will automatically open a new tab where it will start the application so this is

the application that we will be working on it's just a simple website it has here a rotating Jenkins logo and just a bit of text nothing special if this

popup do doesn't show up maybe you have a popup blocker that is not allowing you to open this so this is the address where this application is available over

the Internet essentially so it's this address and a port 3000 now the idea is that when we're working on a project we need to know all

these commands now we don't need to worry exactly for this project which commands we need to run because they can depend from Project to project but the idea is when we're developing this

project Loc Al we are typing all this command now the idea is that we want to automate any manual step but before we

can use Jenkins to automate manual steps we first need to know and understand the steps right so we cannot automate something that we don't know to begin with so we need to get familiar with the

tools that we will be using I've just shown you a few commands but essentially what we want to do in the upcoming lectures is to take these commands and give them to Jenkins so that Jenkins can

do this so I think we already have everything that you need so far I'm going to press control C to stop this process and you'll see here that I'm

returning here to the terminal by the way this is the same terminal that you can use to play around with other commands that we have used so far like

MK deer touch sleep or anything else because this is essentially a Linux shell that you can use the first step in getting this commands

that we have just executed to run in Jenkins as well is to figure out if we have all the tools that we need this npm command is not available on any Linux

environment like commands like touch or MK deer sleep or anything else we have used so far but let me show you what I mean going to go here in Jenkins and

let's just try try out the new experiment I'm going to call this simply test npm because this is the command that we want to use going to use here

Pipeline and let's go to the pipeline itself going to open up here the hello world and let's begin an sh block and

here we can write something like npm D- version so this would be the first check we just want to check is there mpm installed on this agent click on Save

build and we going to take a look at the logs in a second now as you can see here the execution has failed and what we're going to get here back is the following

error so we're running npm D- version but we're getting the error npm not found so we don't even need a project files we don't need a package.json file

we don't even have npm installed to be able to run any of the commands that we did so far in the repository itself now this codes space is kind of like smart it knows what kind of a project we have

and already creates a special image that has all these tools install but Jenkins doesn't know anything about it now to solve this in Jenkins there are two

approaches one approach is to Simply go on the agent or on the agents and manually install npm which is a tool

that comes when we install nodejs which is a platform for running JavaScript now that is option number one the other

option is to use Docker which allows us to use Docker containers as needed the disadvantage with the first approach when it comes to installing all

these tools directly on the agents is that typically Jenkins is supposed to run multiple project now when we are using this project we may need different

versions for example maybe this project is working with node 18 but maybe we have a legacy project that is using node 10 now there are always different

workarounds in order to get something like this working but typically it's not so easy so we may have conflicting versions of these tools now doer allows us to separate this so let me show you

what I mean and how we can use Docker in our pipelines so let's change a bit to the pipeline configuration and I'm going to show you

both running a stage with docker and running a stage without Docker so let's try first without Docker so this will be

the first stage and for example we can simply try out here something like a command that will not cause any issues so let's try

Echo without Docker I'm going to copy this stage and we're going to use with Docker

when we want to use Docker in a stage we need to specify here agent configuration and here within the agent we need to specify the image that we want to use

now we need to specify here a Public Image and what we're going to do here is for example if I want to run something with node we will specify here the image

node and also specific versions for example node 18 and an Alpine is essentially a very slim Linux distribution that is ideal for

cicd so this is how we can specify this image and then inside here we can write for example with Docker so let's test it out and see how this

works seems that I have a small error so let's see here what the problem is still need to make a small change so it's not just the angent itself but we

also need to specify here Docker and then this image configuration is within Ducker okay so now we can go ahead and

try it Stakes happen all the time we just need to quickly understand what's going on and try to fix our pipeline so what is happening next again it is

complaining about Docker and we're getting here the error invalid agent type Docker specified now what is telling us is that

there is no agent which is called Docker and typically this problem is related to the fact that Jenkins isn't configured yet to run with Docker so I'm going to go here to the dashboard because this

enables us to go here to manage Jenkins and then what we can do here is go to the plugins and it's super important that you don't confuse this the first by

default is here updates and sometimes you know this is just about plugins that need updates what we need to do is click here on available plugins

and what we need to do is check if the docker pipeline plugin is available so you will see here Docker pipeline so this is the pipeline

plug-in that we need as I mentioned at the beginning of the course Jenkins is essentially a plugin monster it's just a skeleton and we need to add additional plugins to get the functionality that we

need now in this case we need this Docker pipeline plugin to be able to use Docker in the pipeline I'm going to click here on it stall and additionally we can also

restart Jenkins once this installation is done so you will see here this steps here are pending and once this is done Jenkins will restart this ensures that

we don't have any issues or something like that so it's always a good idea to restart Jenkins after installing a plugin for a lot of plugins you can just install it and use it right away but something isn't working you don't know

exactly is it because the plugin hasn't been installed properly or is it because of something else so let's give Jenkins a few seconds to install this and to

restart okay so now Jenkins is ready to be used again let's go back to our test npm Pipeline and see if it now

works so now we're getting definitely a different value and we can check here and see if there's anything else that's wrong with our configuration so it's essentially

telling us within Docker it's expecting to find something and let's see if there is something that we don't have so we don't have image here

specified so actually the error that I did here you know this sometimes happens can be a bit harder to debug but I actually added here column which I

shouldn't have so it's only image space and then this name of the image going to make sure that there are also no spaces here so it's quite easy as you can see

to make these mistakes and sometimes the errors that you're getting can be quite confusing and you know over time the experience comes but in the beginning

can be quite confusing like what's the problem why doesn't it work okay so now we got this to work but we can still need to see here what's going on so

we're going to check here what is happening in terms of the error so there's no property Alpine for class so this is probably

one of the other errors so I think we're making here like all the errors possible and the idea here is that yes we can specify here something without putting

this between quotes but if we're not putting it in quotes it's going to be a bit more difficult so we can get here an invalid syntax so hopefully six times a

charm let's see if we manage to get this pipeline to work it takes a bit longer so let's see what is happening here in the background so this is the first time so you're

going to have this command here Docker inspect and it's essentially jinking shcking here do I have this image somewhere still locally and if not it's going to use Docker pool to pull this

image from a public repository so this will take a bit of time now this is only valid for the first execution because the first time it takes a bit of time to download this image but next time it

should have this image in Cache essentially and run this job much faster so now it is essentially starting this container after it has been downloaded

you can see here this Docker R command and this is the actual command that we have executed here so it says here with Docker and we're getting the print and then the container is stopped and the

job finishes okay so now we have managed to get this to run let's check if npm is installed here so I'm going to use another sh npm d d

version this is the command that we want to execute so we still going to keep the echo here and we're adding npm Das version to check if it is available here

in this Docker image that we're specifying for our build and we should see that this job is now working much much faster so we had initially 56 seconds to get this to run you'll see

here the second execution is only 4 seconds we can go inside the logs and we can see here that we have now npm installed even though previously on the

agent npm is not installed so we're downloading this Docker image we're running a container then inside the container we can run all these commands that we need and then at the end we can

just destroy the container and essentially terminate the pipeline let's quickly recap what is happening when we have a stage where we're not using Docker and where we have

a stage where we are using Docker so in the stage without Docker controller will find an agent and agent will run for

example this command directly on the agent itself and when there's a Docker image involved the controller will again

find an agent that can run Docker image and then what the agent will do is we'll look at this image we'll download

it if necessary and we'll start a do ER container and then the commands here will be executed in the docker container

itself and then at the end of the execution the container will be stopped so this is the main difference these commands here are executed in the container while when we're not using

Docker any commands will be executed directly on the agent but there is also another important difference and this is what I want to talk about in this lecture and this is related to the

workspace what is happening with the workspace when we have jobs that don't use a container and we have jobs that use a Docker container so let's quickly see how

exactly this is working so we're going to use here the triple quote so that we can write multiple shell commands one after the other and we're going to keep

this Echo Docker because this is useful to know exactly in which job we are running this now apart from this we want to check for example the workspace so we haven't created any files so the

workspace at this point should be empty but we just want to check exactly what is happening in the beginning so we're going to use the command LS which will list all the files that are in the

current workspace where this agent is executing the job and we're going to also pass the flag LA to create list of files and also to show any hidden files

so this will essentially list all the files in the directory where we're running the job now we're going to do pretty much the same thing here as well

so we can pretty much copy this command and we're going to change here sh command so we're going to have here

we're listing all the files we don't need mpm version at this point and we're going to keep here the echo want to make sure that we don't

have too many quotes but I think it looks good okay now let's say that each of these stages creates a file so let's

use the touch command to create a file we can call this container no. txt so

this is the stage that is not using Docker so we're saying here container no and we're going to use here for the darker stage

essentially we can see here container yes so we could theoretically list all the files in the

beginning and run these commands and see what is happening let's go ahead click on save and run this job and see what is happening and we should jump directly to

the logs so that we can understand what is happening here so first of all we're going to take a look at logs we have here without Docker these are essentially the files

that are present so there's practically nothing inside this directory and we creating the file container no what's important also to notice is this

information here and it's telling running on Jenkins and telling here where this is running so it's in VAR Jenkins home workspace this is where all

the workspaces are located and the name of the workspace is test space npm now if we looking here further down

we're going to see here the docker stage starting and it is in bar Jenkins home workspace and it's test space npm at two

H that's interesting and then of course we are starting here the docker container and we can see that we are using Docker we are listing all the

files into the directory and then are creating a new file now as you can notice here as you can notice here there are no files so essentially here we

don't have the file created by the previous stage so what is going on here let's also take a look at the workspace to better understand this so if you're going here at the workspaces we're going

to see now that we actually have two workspaces so we have this first workspace where we have container

no and then we have this other workspace let's go back for a second with add to and we have container yes so essentially

the job without Locker has its own workspace and the job that's running in the container has a separate workspace and sometimes this is something that

makes sense but let's just say that for us this doesn't make sense so if you want all the stages to share the same workspace because there are interdependencies between them

regardless of how these are executed we need to configure Jenkins in a separate way so by Docker whenever we have this Docker configuration here Jen will

create a separate workspace just for this and it's going to be a different workspace compared to the stage that is not using Docker so in order to have a

shared workspace what we need to pass here as an additional configuration is reuse node and we're going to pass here the value through so this is by default

false I'm going to also attach some documentation regarding this functionality as a resource to this lecture but I just wanted to point this out because a lot of people using this they

don't understand why there are so many workspaces popping up here why are there different files in those workspaces and so on and so forth so we need to run

this once and see exactly what's going on I'm going to check here for example the logs of the second execution

so we're going to see here in the second execution now we also have container no now of course if we're going here inside this job execution we're going to see

there is a single workspace and we have both files here so this is what's called workspace synchronization want to make sure that all the stages in the pipeline

use the same workspace especially if there are dependencies between them let's get back to our project and create a simple pipeline that we can execute in Jenkins so if we're going

here back to the code space we may notice after a while that the code space is stopped so if that's the case simply click here on restart code space and in just a few seconds it's going to be up

and running again now what we want to do next is to define the pipeline but in the project itself what we're going to do here is we want to make sure that we're not inside

the directory so just click here in the project itself and then there's this option of creating a new file you will see that this file is created here on the root so at the base of the directory

and we're going to define the Jenkins pipeline in a file which is called Jenkins file and it needs to be written exactly as you see here and I hit here

enter and we can quickly go to Jenkins and use an existing job just to get the structure right so we don't have to really write everything from scratch we can remove everything that we have here

and get started with the sample pipeline so I'm going to copy this go back to the editor paste it here all right so now we have made a change in our project

whenever we making changes in the project we also need to use git to commit them so we're going to see here this indicates that there's a change in

the project and you will see also this Jenkins file appearing in green if we clicking on this I'm going to see here changes Jenkins file so we're gonna add

here a commit message like something like addit Jenkins file and we're going to click here commit next weing ask if you want to automatically stage all

changes this essentially means that we're going to prepare all the changes that we make for a commit so I'm going to select here always so this is something that's not

going to be asked and we have committed these changes but we haven't pushed them yet to the repository so here we just have a local copy essentially running

somewhere so we also need to essentially click on this button to sync these changes and we just going to click here okay don't show again these are the

steps that we need to do when we are working here in this repository now where exactly is this change that we did so if we're going here to GitHub we're

going to see here that we only have one repository and we looking here at the latest changes going to see here that we now have Jenkins file so this is the

Jenkins file that we have just added okay perfect but how can we get this to run in Jenkins well in Jenkins we need to do the following so what we're going

to do here is for example we can delete this pipeline because we don't need it anymore it was just an experiment so from the configuration essentially we're

going to go ahead and remove it we can create a new item and we can call this learn J LS app so this will be the name of the pipeline

name of the job now select pipeline click okay now when we're going here to pipeline we're not going to write the pipeline script here but what we going

to do here is from this select list we're going to select pipeline script from SCM so SCM simply means source code management essentially we're saying we

want to get this from somewhere else we don't want to Define it here we want to get it from somewhere so the sem in this case is going to be

G and next we're being asked for the repository URL so we need to go here to the repository and this needs to be in your project not in the original

project and from code you can go here to local select HTTP and copy this address

go back to Jenkins and paste here the repository URL this is a public repository and we don't need any credentials so Jenkins

will be able to read this if you're configuring a private repository Jenkins also needs credentials but more on that later apart from this there's also the

information regarding which branch to build so when we are working with GitHub creating a new repository by default the

name of that branch is going to be main we used to have master in the past but we're kind of like transitioning to using main as a more inclusive word so

Jenkins here still thinks that Master is the default so we need to change here master in main because this is the name of the brand so we can check again here

you'll see here the name of the branch that we're using is main okay so this is another thing and apart from this we're going to be asked

for the script path essentially where is the Jenkins file and you'll see here there is no path so we just want to make sure that the name of the file is exactly as we have written it here so

I'm copying it I'm quickly searching here I'm going to see here we have the Jenkins file here so the path is also

looking okay I'm going to click here on Save and click click on build now so the execution has been successful what we

see here is an additional stage which we haven't defined in the pipeline but this is something that Jenkins is adding essentially it is cloning the repository so we can take a look here at the logs

you can see exactly what's going on so we're going to see here obtained Jenkins file from so it's telling you oh you got the Jenkins F from this repository telling you where this is running in

which directory and and then it's doing a few things with Git so of course the logs here are a bit more detailed but there's not So Much Information here so we can see which is the commit message

which is exactly the message that we have provided and then we're starting here the stage hello now in a nutshell when we want to

make changes to our pipeline we need to have the code ready so we need to be here in our code workspace we need to commit that change

and push it to the repository and then go to Jenkins and click on build now later on in the course we're going to configure an automated way of

automatically triggering the pipeline every time we're making a change because this is essentially the full automation we don't want to manually trigger it all the time but it's slightly more

complicated to get that up and running so I beg you to be patient and just to remember these steps when you're making a change to the Jenkins file you need to

commit the changes push them and then go to the Jenkins job and manually click on build now to build the new pipeline I invite you to play around with this a

bit especially if you haven't used git before every software project requires a build step some programming languages need to be compiled but in this case in

the case of this application we actually need to create a production build for this web application so essentially files need to be minimized and many other steps that are required for the

final step so there's always something to be done in terms of the build now if you're taking a look here at the documentation we'll be able to see here that essentially in order to create a

production build we need to run the command npm run build so let's do this first here locally in this IDE to understand what exactly is happening in

case the terminal is no longer showing up you can enable it from here right at the top I'm going to click on this and you'll see here the window below popping

up I'm going to paste here the command npm run build so it's going to create an optimized production build and we may get some warnings here but don't need to

worry as long as there's no error we can consider this step as being completed it says here compiled successfully and we also have here a

list of files that have been created so it says here the build folder is ready to be deployed so with this command we have created something inside the build

folder which didn't exist before and the build folder is never part of the git repository so whenever we're creating build artifacts those are not checked

into git so we have this build folder here and it contains different files that are needed for the web application now how can we do the same in Jenkins we're going to jump here to the Jenkins

file and we're going to rename this stage from Hello to build and we also need to use Docker because we need a

Docker image that has node installed so that we can run npm so again we're going to Define here agent the agent will be

Docker and Docker itself will have a configuration where we specify the image and the image is node column and here after the column we specify the tag it's

going to be version 18 and we're going to use Alpine because it's much much smaller apart from this we also want to set the flag reuse node

and we're going to set this to true so now we have the build environment that we need we can start here by adding an sh block so we're going to have here

multiple commands that we need to execute and let's start for example with ls. LA

just to see what is inside the workspace before we start and what is at the end so that we can understand what has happened here what I like to do when we

using different tools is I want to print out the version just to keep this documented somewhere so for example we are having here a node version and node 18 is like the major version but it's

not like an individual version so I like to write right here something like node Das Das version just in case something happens we can take a look at previous

build and see oh we were using Noe 18105 or something like that and the same goes for npm npm also has a version so we can print that as well so this is

something that when we're using these tools that we rely on it's a good idea to do this it's not mandatory doesn't have any impact on the build itself but it's good later on for troubleshooting

now the next step you would think that okay let's run npm build but no npm build doesn't work if we don't have the dependencies installed so these

dependencies in this case are stored in these node modules these node modules are not part of git so when the repository is checked out we don't have node modules need to install them now

we're not going to use here npm install we're going to use another command npm CI this is essentially a command that's designed for cicd servers so instead of

install we're going to use npm C and then after we did this we can use npm run build so then we can run the build

and finally let's take a look at what we have inside the workspace so we're going to list all the files there so I think we have everything we need to get this

to work so let's go ahead and add a commit message and push this changes then we're going to go to the Repository

and hit build now you already take a look at what is happening here so we can see that where is it so we're starting here so this is

essentially the build stage this is the commit message that has triggered this we are using this doer image this doer image is being started this is the first

command that we are executing so I want you to notice that within the files here we don't have no modules and there's also no build folder so this is the list

of all the files and directories available there's no node modules there okay after that we're using here node Das D version so we're getting the exact

node version so we're using the major tag 18 but there is always a specific version the same goes for npm now with npm C we're going to get

here A bunch of warnings we don't need to worry about them as long as there is no error These Warnings are okay we can live them not going to worry about that and let's see what is happening

afterwards the next command executed you will see here the Plus in the beginning is npm run build and it says here creating an optimized production build compiled

successfully it's pretty much the same output that we have seen in the development workspace so this is important to first use the commands somewhere where you can easily troubleshoot them to make sure that they

work as they supposed to work and then when you're ready to automate things you put them in a pipeline because otherwise if something doesn't work there in your workspace and you're putting in pipeline you're just wasting time trying to

troubles shot things in Jenkins you don't know exactly is it a Jenkins problem is it a problem with tool so first try on your own computer or on development workspace like we have and

then put this in jenin all right so we're getting here some information hey this is ready to be deployed so we're taking again a look at the files that we have so we're going to see here node

modules has appeared here and we also have the build so they were not there before of course you can also take a look inside the workspace itself there's

only one workspace we'll see here the build and we'll see here the no modules that have been installed so this is how we can build this

project let's go ahead and expand this Pipeline with another stage so we need to make sure that we are in stages so we can see the stages begin here and end

here and this is the build stage so I'm going to write right below it stage this will be test stage going to surround it with the

brackets and everything and whenever we're learning something new is always super important to make small steps so in this case the only step that we're going to do in this case is to Define

this new stage and simply print a message just to see that the syntax and everything that we have is valid so I'm going to Define also the steps because they're

needed so what we're going to have in terms of steps we can simply use Echo and going to write here test stage I'm going to commit this changes and then go

back to Jenkins and see how this pipeline execution looks like so now if we're taking a look at the pipeline execution we're going to see here that a new stage has been added to the pipeline

and of course we can take a look at logs and see that this is the test stage all right so we're making very good progress but we're still far from actually doing what we're supposed to do in this

assignment so let's move on to the next step which involves checking the build folder and actually the index file in the build folder I'm going to replace

here Echo because this is not really needed with SH what we can use here is test minus F because we're testing for

file and we can check if build SL index.html exists I'm going to commit and push these changes around the pipeline and we're going to take a look at the pipeline

execution going back to the pipeline if we're taking a look at the test stage we'll be able to see that the test command has been executed and there's no

indication of a failure which means that build directory and the index.html files exist there so that's the first part that we wanted to check that the build

artifact is there so that's one useful test now we actually you want to execute the test that are also within the application so the application here has

the source code it's a super simple application we have this app.js file but there's also that app.

test.js this is a super super simple test it kind of like just goes to show that it's possible to write this kind of test within the application at this

level this are typically unit tests that we're running because they are only testing small part of the application they're not testing the entire application so it's quite common that

after the build stage we're also executing this test so let's go ahead and expand sh and we're going to put it in multiple lines

so this would be the syntax that will allow us to have it on multiple lines so we're still going to keep here the test but what we're going to add next is

npm test now npm here needs a not JS environment so this is the moment when we need to bring Docker to the mix of

course we can simply go ahead and write a configuration like this one once again but just going to go ahead and copy it but be very careful where to paste it so

it needs to be here at this indentation level so we're going to have F the stage test and I have agent we're going to keep this image because we still need

the same nodejs version going to go ahead commit and push these changes and in a few seconds we're going to take a look at the pipeline all the execution of the test has been successful you see

we don't have any errors also go directly to the logs and take a look at the entire pipeline execution just to understand what has happened here and

probably the most important part is this one so again we're starting now everything inside the docker container so we running this command to check that we have to build artifact so they're

kind of like super important and then we're running the command npm test this is where we can see that the tests have been executed and we can see one passed one in total so we have only one test

and it has passed it's also a good idea to check the logs to understand exactly how successful execution looks like so in a nutshell this is how our pipeline

looks like we're using the docker image so that we have access to the nodejs runtime environment and then we're executing the npm test command what's super important

to understand about this npm test command is that can also be executed before the build so we don't necessarily need a build to run the test so it's

also possible that we may decide to first run the test and then to the build there are various situations when that may also make sense if you decide to do

something like this super important to understand that there is a dependency between the stages so what does it mean it means that we first expect at this point to run the build and then the test

because inside the build stage we are running this npmi so npmc creates this node on this called modules directory so if you want to play around you can also

try to switch the stages you see that npm test will fail because of some Miss independencies so if you want to run the test stage for the build stage you also

need to run first npmc okay so that is it for this lecture in this lecture we're going to take a look at the steps we need to take

in order to publish a junit test report from Jenkins now wait a minute what is a junit test report generally speaking a

junit report is a file generated by the junit testing framework in Java projects and this file typically uses the XML

format so this report provides detailed information about the results of the different test cases including a pass or

fail status execution times error messages even like other statistics that are relevant these reports are crucial for cicd

because it allows us to automatically take a look at the execution and to identify how many tests have failed and generally to keep track on what exactly

has failed now we could take a look at the logs and see what has been reported there but it's much more convenient to take a look at a Consolidated report our

project does not use Java and it doesn't even use the gunit testing framework but the testing framework that this project

uses can generate reports using the junit format actually this junit format is so popular that essentially every

testing framework has the possibility at least to generate it and to store its test results using this format when we

have executed the npm test command we have executed a test but this test execution has also created a new Direct directory and this directory is the test

results directory because this is how it is configured and inside here we're going to find file which is called jun.

XML in this case we only have one test case it indicates that it has executed successfully and exactly how much time the execution took and so on of course

when we have multiple test this file will be much larger and it's typically not super easy to read it is not designed for us humans to go through

this report but Jenkins can read this file so let me show you how we can configure Jenkins to take a look at this report and to show it to us in a much

nicer way now inside our Jenkins file pipeline we want to publish this Jun report regardless if the execution of the entire pipeline has been successful

or if it has failed so what we can do in that situation is we can go here and and right at the end so where we have the

stages so we have here all the stages you'll see they all finishing here can add here a post action and inside a post action we can

use always because we want to use this always regardless if the build has been successful or not and inside here we're going to use

junit and we will specify junit where the path is all I have to do is right here for example test results

for/ jun.

XML super important that you double check this path and make sure that you don't have any spelling mistakes because then you will get an error because the report cannot be found all right so

let's go ahead and commit these changes and we're going to run the pipeline and see how it looks like the first thing that I want you to notice is this

additional stage here with post action so this is where this junit report is published and at this stage the most important part is not getting any error

so you can see exactly what has happened here in the post stage and what we're going to see here is no suitable checks publisher

found so what does this mean now if you're seeing here this warning or this message checks API no suitable checks publisher found don't worry about this

is it is not an error and this is not an issue what I'm going to do next is going to run this job two or three more times and I'm going to also hit the refresh

button on the page because something should show up and I'm going to show you in a few seconds what will show up after a few executions what you

should notice when refreshing the page is this test result Trend so this will keep track of all the tests that have been executed over time and if some

tests start failing this trend of course will go down you're adding more tests then the trend will go up but this is also clickable so you can get additional information about the test results here

you'll see here this is the seventh build and we have here the test result says no failures we can click on it and we can also go through the test that are

being listed here so it's only one test and we're going to see here the status of this test is passed so just nothing super important about this but it's going to give you additional details and

if something is failing it's going to be a bit easier to identify which test exactly has failed this is the main reason why we like to have this

integration in Jenkins why we want to have this test being displayed here in this section we will learn about deployments and take our website project

and deploy it to the cloud using a very popular platform called netlify along the way we'll learn about other devops practices such as

continuous delivery and continuous deployment by the end of this section we will have a complete cicd pipeline that will take our website build it test it

and let it float in the cloud to follow along with the section you will need to sign up for a free account at netlify the process is super

easy and and takes only 2 minutes you can use your GitHub account to sign up or just provide your email and a password after you have verified your

email there are just a few questions you need to answer when asked about deploying your first project just select skip this step for now and soon you

should see this page if you manage to do this you're all good for now just a quick reminder in case you get stuck or something does not work check the course

Q&A for similar issues or look for the troubleshooting lectures which are spread throughout the section are ready to deploy this application to the cloud then let's

begin let's begin by manually deploying the application as a resource to this lecture you will find a zip

archive download that asset and if you unzip it you should have a build directory containing one index.html

file once you have that from this screen we're going to select here deploy manually so essentially you can drag and

drop that entire build folder here or simply click here on browse to upload so this is the zip file and this is the build directory so I'm going to

select the build directory and simply click on upload and this entire directory will be uploaded so I'm going to click again here because I trust this website going to see here uploading

please don't refresh so this will take just a few seconds and then we're going to get this message here deploy success

so by default netlify has created an address for us and has deployed our web application so in this case the randomly

generated name is this one and by clicking here on on open production deploy going to see my test website this

is essentially a much smaller version it only contains one file but is enough to test that this manual deployment is

working so just again you will see here that you will get your own random name and this will be the address of your application so whenever you want to check your application you'll have to

access this URL but for you the URL will be different if you create multiple websites each website will get its own name of course we can go ahead and

configure a few things so for example we can change the site name but ideally you should put here something random because you cannot select every name I'm just going to go with this one it's absolutely fine just

wanted to mention that you can change this name in the upcoming lectures we will do this exact steps of uploading deploying and testing our web

application but this time we'll do everything from Jenkins typically when we're trying to automate something we need to understand what are the manual steps that we're doing in order to be

able to automate something so in this case the manual steps are getting that particular directory uploading it letting netlify do its job and then going to the website and checking okay

was this deployment successful or not this course is a shorter version of a larger Jenkins course that has over 10 hours of content I've cut down the

content to cover the basics of cic because of this some steps have been left out and you might see that the Jenkins files in the upcoming lectures

looks a bit different this is mainly because a new end to endend Stage that has been added as well as the parallel execution of the end to end stage and

the unit test stage don't worry about these differences you can still follow along with A continuous deploy ment section you can use all the steps shown in the upcoming lectures on your current

pipeline for more details please check the course notes the next question is how can we get Jenkins to open netlify.com then

select this particular website that we have configured here then go here to deploys select the files that need to be uploaded and then essentially upload

them and generate the deployment well the thing is we don't have to this is not how automation Works automation tool like Jenkins does not open applications

do not open browsers does not click on buttons or select files this is not how things work in the automation world we always need to work with the particular

tool to be able to replicate any manual steps that we do now luckily netlify does have a tool it's called netlify CLI

netlify command line interface so essentially a C would allow Jenkins to interact with netlify for example to log in to upload files and do many other

things without actually leaving the terminal so this is all command based Jenkins will not have to open a browser window or do anything like that now in

order to use netlify CLI in Jenkins we need to install it it uses the not package manager which is available in node so that is something that we have

used before and it should make our life a bit easier and this is the command that we need to run to install netlify CLI and this is what we're going to try to do in this lecture I'm going to jump

here to the Jenkins file and we're going to start here with the build job by copying it because it already has the structure that we need then here in the test we're going

to collapse these I'm going to click on this so see here that everything is looking much better we can see exactly

at which level we need to paste this going to call the stage deploy and we're going to check a few things that we already have so we're using Docker we need this because we

want to use the node.js runtime this is what has npm already installed we already have reuse node because later on we need access to the workspace all the

commands that are here this is something that is not really interesting for us so what we're going to use here from the documentation is essentially this installation command I'm going to copy this

I'm going to paste it here in this block and apart from this we should also check if afterwards netlify has been properly installed I'm going to run the command

netlify Das Dash version now there's one thing I wanted to point out and This Is This Global flag we've seen this before

and for example when we try to install here serve we had issues with a global flag so let's see if those issues persist going to commit these changes and we're going to take a look at the

pipeline in a few seconds if we're taking a look at the pipeline we're going to see here the deploy stage that has been added after the test but if we're taking a look at

the logs we're going to see here that there's a problem installing netlify and again we get this permission denied error that we seen before so in that

scenario we need to go back to our configuration drop this flag and essentially when we're trying to use use netlify it's going to be

available in this same directory node modules. bin and then netlify or at

modules. bin and then netlify or at least that's the theory so let's see if this is working properly so now we're installing netlify CLI as the local

dependency to our project and then we're using it we're calling it directly from the node modules going to commit these changes and we're going to take a look at the pipeline now if we're taking a look at

the pipeline execution we're going to see here that the deploy page is now successful we can quickly take a look at logs and we're going to see here that we

are installing netlify CLI we're getting some warnings these are not errors so don't worry about them essentially in the end here if you're getting something similar to this means that everything

has been installed successfully and we see here the next plus sign which means that we're running the next command we're getting back here netlify CLI and the specific version of netlify that we

now have installed of course it would have been possible to have netlify part of the project dependencies and store this package.json

that it's also way to do it just want to show you another way on how you can have this in case it's not part of the project itself and you need to install it it's also a good way to know how to

install other tools that are not part of your project the next step in preparing J to actually deploy this application is to

configure the domain itself essentially we need to tell netlify CLI which application we want to deploy and this is done by configuring an environment

variable we're going to go here from netlify and I'm want to make sure that I have the right application selected I'm here at site overview then if I click on

site configuration what we're going to get here is the site ID this is essentially the identifier of the site we don't want to go by the site name because this is

something that we can change but we want to use here the site ID so this is the unique identifier for the website I have this identifier in your account you will

get different identifier but as a first step what we want to do is we want to store this site ID in our Jenkins file configuration so in order to do that

going to go here to Jenkins file and we're going to go ahead and Define here environment variabl I'm going to write here block called environment and the

name of the environment variable needs to be exactly as I write it here all in upper case without any spelling mistakes hopefully so it's

netlify underscore sitecore ID equal and then we're going to use the value that we see here in the account so this is a copy button I'm going to use

that as as I mentioned your site ID will be different it's super important that we name this environment variable as it is

because then netlify will know about this it automatically checks if this environment variable has been set and if

it has been set and it's no oh this person wants to deploy this specific application of course in our code we can simply check if everything has been prop

properly configured so we can go here all the way down to the deploy and for example we can have here an echo

statement and we can write something like deploying to production site ID and then we'll get the site ID we can

specify here the name of the site ID so let's go ahead commit these changes and see if we have properly set and use this environment variable so the execution of the PIP

plan has been successful let's take a look here at the deploy stage and see if we can find our message here in the logs so see here deploying to production and

we have here the site ID so this is essentially the variable that we have set earlier in the configuration so it seems to be working properly even if we have installed

netlify CLI even if we have configured our site ID as an environment variable it does not mean that Jenkins is authorized to deploy our application why

because we haven't provided any secrets essentially we haven't provided our username and password we haven't provided our email or anything like that so if a deployment would be so easy

anyone could essentially take over our account and deploy something else on our website this of course something that we don't want so what we will do in this lecture

is to generate a token which will allow Jenkins to use the netlify CLI to deploy our application now why aren't we just

providing the username and password quite often using a token is much more convenient you can think about a token as sort of like a temporary password

something that provides access to the account but it's nothing that you can use to log in so some actions are possible others are more limited and from a security standpoint it's possible

to create a token that only has limited access so we're going to use tokens a lot when using CLI tools and this is just one of the examples so how can we

generate one of these tokens well the main idea is that we're going to go here to our profile going to go here to user settings and from the user settings

going to select here applications I'm going to scroll a bit further down until we see here personal access tokens and what we're going to do here is we're going to click on new

access token and you will see here this access token has a few interesting things so first of all I'm going to give here description so the description will be

Jenkins because it will help us remember why we have created this token apart from this there's also an expiration here I highly recommend here selecting

an expiration like 30 days or 60 days depending on how long you think will need this uh generally not a good idea to create something with no expiration

unless you really want to have it like forever rotating this credential is always a good idea but let's put here 60 days that should be more than enough go

ahead and generate token and this is the token now how can we use this in Jenkins should we go to our Jenkins file and

Define another environment variable no absolutely not we never store secrets in a Jenkins configuration Secrets have

their own place in Jenkins and as the next step we're going to go to Jenkins and securely store this credential so here's what we're going to do here and

to go to Jenkins going to go to the dashboard from the dashboard going to go to manage Jenkins and the next step would be to go here to

credentials so this is where where we can manage the credentials I'm going to select system Global credentials and the next step would be to click here on ADD

credentials so the kind of credential that we're going to add is not username with password which is by default but actually secret text so we only have

like a small secret text that we want to store here and there are a few things that we want to make sure the scope is selected to Global by default so this is

what we want to have here of course we also need to base the secret that we have so this is going to be from netlify going to copy it don't use the same

secret because I'm going to invalidate this after the recording so this will definitely not work you need to use your own secret for this and then the ID will

be netlify Das token so this is the name that I will choose for this it's important to remember this ID because we will reference this ID in the pipeline

later on so make sure that you have written everything as expected I don't see any issues netlify Das token looks

good and I go ahead and create it don't want to store it in Firefox so you see this netlify token will appear here if you click on it again you can update

value but this value will not be revealed so it's concealed here it's hidden so this is why we are now in trusting J Lings with this particular

information we'll be able to reference it in our pipeline but it is essentially safe we cannot simply go ahead and expose this token in a way that will

endanger our netlify account so this is how we can generate a secret nfy and securely store it in

Jenkins for the authentication to work netlify CLI expects an environment variable named netlify

oore token let's go ahead and write it here so it's going to be netlify underscore off underscore token so it needs to be exactly like this

because netlify CLI will look for this variable like it also does for the site ID if it finds it variable it's going to use the token that we are specifying

here now we can simply go ahead and put the token here but as I mentioned earlier is not a good idea we should use the credential that we have stored in

Jenkins so in order to use that credential we're going to keep here the equal sign but we're going to use here the credentials Helper and here this is the place where we need the credential

ID just in case you have forgotten the credential ID simply go to manage Jenkins credentials system Global credentials and this is the name of the credential

okay so it's netlify Das token I'm going to copy it from here because by copying I'm making sure I'm not making any mistakes all

right so now we have the netlify site ID we have the authentication token which we're grabbing using credentials helper this is not exposed in the configuration

but that's very good now we need to check that everything is working fine so we're going to use here a command which is called status so using the netlify CLI we're going to use a command called

status in case you're wondering like how do you know which commands to use netlify CI has a command reference with a lot of the commands that we can use

for example also status so status will just print some status information it's just sufficient to check that everything that we have is actually configured correctly so we're going to go here to

the Jenkins file I'm going to copy this exact command that we have here but now instead of typing Das Das version we're going to use netlify

status and this should print status information going to commit these changes and we're going to take a look at the pipeline in a few seconds let's take a quick look at the pipeline execution so the deployed stage is

successful we going also check the locks here so what do we see here there are a few important information we have here the netlify version so this is something

we've seen before the last Comm command is this one netlify status so it's telling us the current netlify user and it's also providing site information so

we know the current website we know where the site URL is and also the site ID so if you're seeing this it means that the entire authentication has been successfully you're not seeing this

check again your token and see if there's any issues there there are no spaces or anything like that in the token itself I've also added a troubleshooting

lecture after this in case you're facing any issues at this step if you're seeing this or something similar to this means that everything is okay and we can then proceed with deploying this

application now we have everything in place to actually and finally deploy our application to netlify so in order to deploy we want to

check again the netlify CLI and we're going to use here the deploy command this command is not the most trivial one but I'm going to walk you through this step by step now first of all there are

a few things that we can configure with environment variables this is the netlify O token so I'm going to copy it from here and use crlf to search you see

here this token is already defined here this is how we're providing the credentials that's the first step second thing that we provide is the site ID so again going to use the the search

function here going to search for the site ID so we got it once here and once here so we already have this two environment variable so let's see what

we need next so here from deploy going to copy what we have here so the name of the command is deploy I'm going to replace status with

deploy now apart from this we also need to tell netlify which is the directory that we want to deploy netlify cannot simply know oh it's the build directory

that you want to deploy right so we need to specify that as well now these commands they have a lot of flags and they're all described here so one of

these flags is the deer flag which will specify which folder to deploy so all we have to write here in our

configuration is Das Dash deer equal and the folder that we want to deploy is called build so this is where our build

directory is now apart from this we also want to deploy to production and there's another flag which is called prod so

we're going to specify that flag as well so Das Das prod so we are specifying to netlify deploy we want to deploy the build folder and we want to deploy to

production right I'm going to commit these changes run the pipeline and see what is happening okay so the pipeline is successful this is very very exciting

let's take a look at the logs to see if everything worked as expected I'm going to scroll here all the way down and what do we see this is

essentially the deploy command so this is the part that's most interesting for us so we're going to see here deploying path so we're going to see here the build folder we have only specified a

relative path this is the absolute path it's doing a few things here waiting for the deoy uploading files blah blah blah essentially the deployment has been

successful now how do we know if the deployment has been successful well there may be no errors maybe here even the job somehow is successful without as

checking the logs we should also manually check to see if the deployment has been successful so we can click here on the website URL and we're going to see here we are

at netlify apppp and this is our application name and we no longer see that ugly page that we have manually updated we now see this beautiful page

here so it means now that with this manual test we can conclude that our deployment has been successful of course we want to exclude ourselves from the

picture we want to take care in upcoming lectures that we don't have to do this manual step here's my face again and this probably means we are getting close to

to the end of the course but don't go away just yet I know time flies by when you are learning and having fun while this course might be ending here on

YouTube your journey with Jenkins doesn't have to stop everything I've been teaching you in this course is completely useless without three additional skills you should learn as a

devops professional Linux commands Docker and Cloud deployment that's why I've created a complete Jenkins course for people new to devops and

cicd this course is a direct continuation of everything with covered here but we will dive deeper into Jenkins building Docker containers

optimizing pipeline speeds and even Cloud deployments using AWS plus will cover essential Linux commands that every devops professional should know

I'm offering this course at an incredible discount for everyone who has watched this online course use the link you see right now on the screen or check

the course notes for the last lecture if this course was useful and in just of couple of hours you learn so much imagine what you can do with a course that has more than 10 hours of

content but if you have got enough value as it is thank you for your time please give this video a like and leave a comment down below for the algorithm this way others can find it as well and

if you click on that subscribe button you might see more content from me thank you for your time and dedication I hope to see you in the advanced course and

until then take care and bye-bye

Loading...

Loading video analysis...