Multibranch Pipeline in Jenkins | Webhook for Multibranch pipeline | Multibranch Pipeline for Git

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends welcome back to galaxy technologies in this video we are going to see what is multi branch pipeline how does it work and how can we enable this one by using web hook first let's understand what is multi branch pipeline hopefully most of you know what is multi branch pipeline but quickly i may explain just i search for what is multi branch pipeline and jenkins dot io is giving some information let's open this and you can see here if you read this definition the main point is here that is jenkins automatically discovers manages and executes pipelines executes pipelines for branches which contains jenkins file in the source control so what they are trying to explain is it is going to create a pipeline for each branch in our source code management system which means that repository where it finds the jenkins file okay for a quick understanding let's take an example that we have three branches in our repository and three are containing the jenkins file then if we create a multi branch pipeline it creates three pipelines under one for each branch whereas if we have three branches out of three branches we have jenkins file only in two branches and one branch doesn't contains the jenkins well then it creates two pipelines where it find the jenkins file anyway we are going to see this one with practical for this demonstration i am using my git repository here we have a repository called test node.js application which contains master and dev branches so whenever i create a multi-branch pipeline for this repository it should create two pipelines and one for each branch all right and this is my jenkins server where i am going to create our pipeline and also i have documented entire this process in medium.com with the title multi branch pipeline on jenkins with webhook and just go through with this one with screenshots i have prepared if you like this one just give applause this definitely helps me okay i have given the detailed instruction how to do this one anyway let's go back and create our multi branch pipeline so to create multi branch pipeline choose new item here i am giving test multi branch pipeline okay and we should choose multi-branch pipeline over here to get this option we should install pipeline plug-in otherwise you cannot see this option okay let's choose this one and we need to give the display name i am giving display name also same and the description also same next branch source for which repository we should create the branches so add source we have a git repository so there is a some limitation over here it can able to create multi branches for git and bitbucket if i am not wrong so let's give the project repository name anyway we are already opened it let's copy it and provide the url next thing credentials in case if it is a private repository provide your credentials or else we can add it i think i have explained this in my other lectures next behaviors discover branches there are some limitations you can provide by using these options but it is depends upon the necessity in our case we are creating branches for all the branches so i am not choosing anything over here next one build configuration i am telling to use the jenkins file so wherever it finds the jenkins file in the repository it is going to create it now where the jenkins file is located it is under root location right nothing but so once we have opened this repository immediately we could able to find the jenkins file so that's the reason just we need to provide jenkins file if it is in the sub directory we have directory and under the directory then we should provide the detailed path and anyway i just want to quickly show you that we have jenkins file on master branch as well as on dev branch so now dev branch here also jenkins file is there let's go back and this is all our we need to leave it like this and scan multi branch pipeline we'll talk about this one bit later let's apply and save it now what it should do it should be able to create the pipeline for each branch in our repository so as i shown you two branches are there it should create the repo pipeline for each branch so it is going to scan it and it create the branches so it is not refreshed i think let me refresh it you can see here two pipelines has been created and one for dev branch another one for master branch and if i just open this one you can see it has been executed successfully okay and our jenkins file is quite simple let me open and show you so it is going to do the install dependencies npm install then test just i am using echo command here also deploy node.js application also echo command so it is quite simple one so it has been executed successfully all right so this is how we can create a multi branch pipeline for our repository all right now we need to test if we create a new branch whether it is going to create a repo pipeline or not okay for that we can create the branch from here nothing but from our github itself or else from our git bash okay for now so for now i'm going to create a repository from here so just we need to create a stage okay i'm creating a new branch called stage and it is copying from the dev because dev is highlighted now if you want to copy it from the master choose master and stays now it is going to create out of master all right a new branch has been created over here that is stage and if i go to my jenkins it won't be triggered automatically why because we need to scan it manually you can see the option scan multi branch pipeline now if we scan it it is going to identify the new branch and it creates the new pipeline for the new branch yes you can see here build queue one that is stage branch it has identified and it is going to create the branch for that it has been executed i think let me refresh it yes you can see here stage branch has been created and job is running and job also successful so this is how we are going to create pipelines for our branches by using multi branch pipeline next thing what we are going to do is how can we enable the automatic build whenever there is some changes in our branch okay for that we need to enable the multi branch scan webhook okay so if you go through with this document i have already explained how to install that plugin and how we can do but anyway i'm going to show you quickly we should have one additional plugin let me show you go to manage jenkins manage plugins installed and if i search for okay yep multi branch scan webhook trigger this is the plugin we should have to enable the web hook on the multi branch pipeline and if you open this one they will give the detailed information and how to enable it okay anyway same thing i have documented over here you can go through with this document in case if you are missing any steps go back over here now let's enable the webhook for our job so our job is test multi branch pipeline let me open this and go to configure and if you scroll down you can see here scan multi branch pipeline triggers this will come only if we install this plugin if we don't install this plugin you cannot see this option now scan web hook if you select this one it is asking for the trigger token so we should provide any random trigger in this case i am giving my token sorry not trigger it is token so we need to give the my token and also if you click on this question mark it will give that the token to match which webhook token and this is the url it is giving so we should provide this jenkins url multi branch pipeline webhook trigger slash invoke sounds also in our github repository if we give this one then whenever there is some changes in our github repository it automatically initiates this job so let me copy this one and go back and to enable webhook go to settings and web hooks here we need to add our web hook okay so far there is no web hook that's the reason we manually has to scan if there is any changes okay so yep yep before testing it out i will do quickly one change and i will show you that build is not going to happen so let me clone the repository onto my local git clone okay i'm not giving anything i haven't saved it so clone the repository okay i'm on master branch what i will do i will just do some changes to my jenkins file just i'm removing node.js just for testing so git status get add dot git commit minus m updated node sorry jenkins file git push origin master okay i just pushed my changes even though this changes get reflect over here in my branch we cannot able to see any execution on our jenkins you can see here 15 seconds ago it has been updated and what i can say it has anyway if i enable also you cannot able to see but i'm not enabling let me open in the new and you can see here still it is executed eight minutes before okay now we are enabling this i have copied it so i have copied it just apply and save and we haven't enabled it yet so go back webhooks and add webhook and copy the url oops i missed it let me open the configure and copy it again and just we need to replace this one with our jenkins url so this is our jenkins url okay slash i removed removed at the end it should be my token right so i just enabled it and we should change it to the application json and add webhook so once you have added it would be like this which means that webhook has been enabled and let me refresh it it should come as a tick mark which means that it is successfully connected with our jenkins server now what i will do i am going to do some changes again on any one of the branch whenever we do changes it automatically initiate the web hook job i mean to say our jenkins job okay oops since it has been executed i think i have saved the configurations before doing some changes or what but anyway let me do the changes again and we'll see i'm just editing readme file so va read me file okay just removed one line on the kit status get add dot get commit minus m updated readme file okay and git push origin master i am pushing changes onto master once it is updated in our repository this is our repository right it automatically initiates the job so 12 minutes before and let me refresh so two minutes before the job has been executed i'm not sure why yep three minutes ago now it should be able to execute yep you can see here multi branch pipeline it is executing 8.7 seconds ago okay so this is how it can be done one last thing i am going to do as i discussed with you if it cannot find the jenkins file in the branch it cannot able to create the pipeline right so now to test it i am going to remove the jenkins file from the stage branch so git checkout stage so i have switched on to stage now we have jenkins file over here rm minus rf jenkins i'm removing jenkins file git status get add dot git commit minus m removed jenkins file okay once we have committed these changes git push origin stage right so once we committed these changes on the stage branch it could able to identified by the jenkins and jenkins should trigger the job and it cannot able to find the jenkins file on the stage branch and it should remove this pipeline so let me refresh it over here yeah stage has been recent update and if i go to stage there is no jenkins file and if i go here it should be queued and it should delete the stage branch okay it is not yet updated or what let me refresh it yep you can see here it is already executed it removed the stage branch again if i add it back okay quickly i will add it so file is here right in there oops master branch jenkins file let me copy it and add it to the jenkins file and save it and add that git commit added jenkins file git push origin stage so again i have added jenkins file back to stage branch yeah so stage branch jenkins file is there and if i go here yep it can able to identify the jenkins file on the stage branch again it is creating the new pipeline for the stage branch all right so this is how the multi branch pipeline we can create and we can enable the web hook on top of this one hope this video helps you if you like this video give thumbs up and if you feel that it is helpful for your friends please share with them and also just go through with the medium article if you like it please do your appreciations over here thank you so much and see you in the next video
Info
Channel: Valaxy Technologies
Views: 18,542
Rating: undefined out of 5
Keywords: aws, devops, valaxy technologies, security, automation, serverless, lambda, linux, linux basics, multibranch pipeline, jenkins multibranch pipeline, webhook for multibranch pipeline, Multibranch Scan Webhook Trigger, Multibranch pipeline with jenkins webhook, multibranch pipeline with github webhook, what is multibranch pipeline, how to enable webhook for multibranch pipeline, webhook for jenkins
Id: fo36b23cpIU
Channel Id: undefined
Length: 16min 26sec (986 seconds)
Published: Wed Feb 03 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.