Jenkins Notes
Jenkins Notes
pipeline > Configuration Configure Script? > pipetinet 2 gent any & General ‘ Seage( ode" ){ s° steps é tho "helo" 2 Advanced Project Options z ,? ES Seage("buit we Steps @ Fi au sh ‘eal 16(@0a3 2 ) a > he seape( "deploy" Ye is: stepet 16 on u Rouen Phe Fe uptime Fey rane » a > 2 Be} mh lick on build, you will see the o/p like given below Pipeline pipeline Stage View ueage age tines 1m ns Variables : variables are used to store the ualues (or) data, Here, we are having 2 types of variables 1. Global variable2. Local variable Global variable ‘© Here, we're declaring the environment variable after the agent. '* And we have to use Svariable in stages to call the variables Dashboard > pipeline > Configuration enpe 1+ pipeline { 5 Tane="Sandeep chikeals” 6 3 3 eee a Stabe elo") ( | ‘er rd ‘ecto "ni, my mane 1s Sane’ a > 2 ’ Bo) | athe Fes Nm = - Click on build and click on logs to see the output Multiple Global variables Dacibond_> pene» coniguration Configure sme ; ewer h P havanced Projet Options z Pec to EL yan ann me « ® »?Click on build and click on logs to see the output Local variable ‘© Local variable override the Global variable '* We're declaring local variable inside the stages Dashboard > pipeline > Configuration Configure $B General 5 P avoncea erject options Alene: ® Preslne a Pah wy a te = agetnad va tite) { i vir ( s we anaeentee 3 : B. sr z ho n,n Sat aa Click on build and here we have 2 stages. First is global and second is local variable. Now, you can easily find out the difference between local and globalSo, when we're using local variable means, some specific/particular stage we need another value. On that case we're using local This is all about local and global variables CO Parameters pipeline Instead of manually selecting parameters, we can write the code in pipeline «© For the first time build, Automatically selecting the parameters based on our code. © for the 1st build -. code will executed After 1st build, Go to configure and check the parameters selected (or) not and do save © For the second time build, click on build with parameters, we can see the output. © for the 2nd build parameters executed Here, Overall we have to build 2 times to see our output © We have to take parameters block after the agent Whenever we're using parameters we don’t need to use Environment block String parameter pipeline Dashboard > pipeline > Configuration Script? 1 pipeline { 5° parameters 6 string(naeg:"persan”, defaultValue: "Sandeep", description:"") 7 8 Sy stapes 18> stoge( Halo") { re steps { n th ' echo “hi my name is Sperson” * B } 1 » ae \ 3 16\} Apply This is our code, click on save and build. Here, our code will get executed Om prc prams ? Configure . . @ ones! ame Pravin One = 2 Metne tnt oe© After the first time build, Automatically selecting the parameters based on our code. B tun Pipeline pipeline Dounce: sun © contgue sons BE oven ratsoge vw ep «- 2 recone © Click on build with parameters, you will get above image and now click on build Eee This is all about string parameters Boolean parameter pipetine mattent > rehne B cSigtleson conf Foie st y Galen pete ( FE sasmced jet pions @ Ppsine This is our code, click on save and build. Here, our code will get executedas. © After the first time build, Automatically selecting the parameters based on our code. 8 sw Pipeline pipeline chugs ne bl eine D bad wth uate Be © Comore Haters Pipatne ap - © futsape ew © Click on build with parameters, you will get above image and now click on build # Inthe aboue code We written defaultValue is true. So, db checkbox is enabled. if we write false itis disabled Choice parameter pipeline Dashboard > pipeline > Configuration serge? + pipeline { siU"sandeep", “chibeals","sandy", “babu” J, description") age ‘chice Paraeter") Sh "echo “touch $f2ea > so i609 This is our code, click on save and build. Here, our code will get executed After the first time build, Automatically selecting the parameters based on our code. B sms Pipeline pipeline > om > o © seve a 2 reosme © Pete star © Here, we select the file names based on our requirements ‘© Click on build with parameters, you will get above image and now click on build Stage Logs (Choice Parameter) After build click on logs we can see the output C Input function pipelineIt takes the input from the user, based on the input it will performs the operations © Here, we are taking the input from the user © If User said OK means build will happen © If User said NO means build will fait So, here we are having one condition. That condition we can called input function © Here continuous integration performed. ie... build +test ‘© But when it comes to deploy stage. It has to be asked the input from the user Real-time Scenario : ‘© Whenever you're doing deployment, this input function we have to give to approval manager. So, manager check everything. if everything is correct he will click OK ie., he will approve the deployment © Here, how we're giving the permissions means we're using role based strategy aind for all managers we have to give full build perform permissions. Dashboard > pipeline > Configuration 3 agent any stages { ceage( Tonat fonrt On VY th? echO\cht ay, tne 4s sandeep" 8 np . n massage "Jore you sre 7° “ ¥ oi Click on save and build you will get below image Input function Average stage times: 168ms meray =gw aS SE Here, if we click on yes means build will success, Click on abort means build aborted/stopped ‘Once you click on yes, you will get below image eaten) 1 shat Spt 00 my nae nde" (tr 7 This is all about input function C Post Build Actions/Functions pipeline ‘A Jenkins Post-build action is a task executed after the build has been completed © When you perform build, you won't care about the build whether it is success(or) fail. Automatically, {you want to build the particular stage ‘© on that case we're using post build actions Here, we are having post conditions in jenkins 1. Always 2. Success 3. Failure Success: When the above stage build gets success means, then the post block will executed Dashboard > pipeline > Configuration Stript\? A: Mipetine ae ages’ ue success{ 2 echo “This is post build success* n > uo}click on save and build When the above stage build gets failed means, then the post block will executed Dashboard > pipeline > Configuration Script a> pipetine ¢ 2" agent any B+ Stopes n Stage ‘Post butld Actions") { = Steps ( * crak my mame fe cari 2 sth °Vhds Jy Oke busta Wastare™ 2 ) Bo sy cA click on save and build When the above stage build either success (or) Failure. This post block don’t care it will always executedSaiipt 2 1+ pipeline ¢ 2 agent any be Hite? S seage(-Post Bula fettone Success’) so steps Z eho ont ents Le eaney” 3 3 ° > a. stage( ‘Pose bulld Actions") ¢ ae ops { 5 eet ay mene do sandeap™ aD Bo Phe is echo "This is post build always" Hoo} _ lick on save and build This is all about Post-Build Actions Setup for Master & Slaue 1. Launch 3 instances at a time with key-pair, because for server to server communication we are using ey-pair. ‘a. Here name the 3 instances like master, slave-1, slave-2 for better understanding b._ Inmaster server do jenkins setup €_Inslave servers you have to install one dependency i.e., java. d. Here, in master server whatever the java version you installed right, same you have to install the same version in slave server. 2. Open Jenkins-master server and do setup ‘a. Here Go to manage jenkins -. click on set up agent (or) Go to manage jenkins -- nodes & clouds - click on new node ~- Give node name any - click on permanent agent and createNew node b. Number of executors - © Default we have 2 executors. © Maximum we can take 5 executors If we take more executors then build will perform speed and parallely we can do some other builds. For that purpose we are taking this nodes ¢. Remote root directory - © we have to give slave server path. Here, jenkins related information stored here So, on that remote path jenkins folder created. we can see build details, workspace, etc... d. Labels - © When creating a stave node, Jenkins allows us to tag a stave node with a label © Labels represent a way of naming one or more slaves © Here we can give environment (or) slave names © ive, dev server - take dev © production server means take prod (or) take linux, dockere. Usage - © Usage describing, how we are using that labels .! ‘© Whenever label is matches to the server then only build will perform © ie,, select “only build jobs with Label expressions matching this node” f. Launch method - © It describes how we are launching master & slave server © Here, we are launching this agents via SSH connection 4g. Host - © Here, we have to give slave server public IP address h. Credentials - © Here, we are using our key-pair pem file in SSH connection © Here, In the key you have to add the slave key-pair pem data©. click on add and select this credentials g, Host Key Verification Strategy - © Here, when you are communicating from one server to another server, on that time if you don’t want verification means © we can select “Non verifying verification strategy” option h. Availability - © We need our Agent always must be running ie, keep this agent online as much as possible a ee Bese) Perform above steps and Click on save Here, if everything is success means we will get like below image oe ee o tmnt ame et ck pena = (o mmm Note: Sometimes in Build Executor status under, It will shows one error. That is dependency issue. For that one you have to install the same java version in stave server, which we installed in master server Now, create the pipeline for master-slaveDashboard > pipeline > Configuration Pipeline script Serint 2 1+ pipeLineg Ze agent { 3 abel "Linux" 5+ stages & stage("naster-slave") 7 stane( 8 sh ‘touch sandy’ 3 , 10 } “oT ‘Save and Build and see the output. Now, go to the jenkins path & check This is all about Jenkins o I f