Java CI/CD using Azure DevOps

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi developers and this video will learn how to create the ICD pipelines for a java application using Azure DevOps we'll start by the CI pipeline where we'll take a sample java application that uses Springwood then we run the command maven clean package this command will degenerate the package which is our jar file then from the CD pipeline will deploy this jar file into an application running on Azure ampersand allow Microsoft MVP join me in this video to show you demo on how to create this pipeline for java application let's first start with the application source code here i have the application opening and vs code my application is a java application that uses Springwood for that here i have a controller this controller have an endpoint for index this index will just return a message saying greetings from Springwood so this is a like a static webpage that we return this message with this application we have an integration test for that here if I go to my controller test Java file here I have here my test which will go try to invoke that endpoint URL for the index then it will make sure that the return is 200 okay and then it will check that the message displayed and that page is the one saying greetings from Springwood so this is a pretty simple unit test to start with only one to build this application and our local machines what we do is to run the built or the maven command if you want to use a maven or you can also use a grater or whatever here with a maven we use the command maven clean package and then we give it the path for our upon XML file the poem XML file is the file that contains the configuration and all the information required by maven in order to build the application source code I have already pushed this application and to get help for that here if you go to this github repository you will find the applications source code and that's the first step required in order to start creating the C ICD pipelines we can call it as the step number zero before I start creating your pipelines now we want to start creating the pipeline's so we have many tools available on the market today we have tools like a ver cloudBees code fresh good shape go we have also Jenkins the most known Travis CI steam City and many more today I'll be using the azure DevOps or edge of pipelines which were created by Microsoft so to start with using Azure DevOps you can go to visual studio dot microsoft.com and from here you can pick your DevOps formerly VSDs and you start creating a free account it's free to use up to five users I have already done that so now I'm logged into my Ezra devops portal and from here I have some projects that I have created before and now we want to create a new project for my java application for that here I have this blue button create project I'll give a name to my project I can give a description for my project then here I choose two visibility for my project to be public so that people can see the CI CD pipelines the logs coming from those pipelines then I go and said create here are the web started creating a project for my application this will take some seconds so would wait then I'll join you later once the project is created from here what I can do I can go to this a menu where here I have pipelines and from the menu pipelines we have builds and releases the builds are for defining the CI pipelines and the build the releases are for defining these CD pipelines let's start with the build so I click on builds then I start creating a new pipeline and from here a DevOps will ask from where you want to get the applications source code so application source code could be on github or on Azure repo inside edge of DevOps itself or it could be in any a github Enterprise version my code job is our micro source is on github for that I choose your github we need a DevOps needs to get access to my github account needs to talk to github REST API for that here I need to create a connection between our DevOps and github the way to do that is here by clicking this authorize using OAuth button this will display a pop-up and here all I need to do is to to connect to my github account it is already done for me because I have already connected before but you will need to grant access to your github account once that's done now I can get access to all my github repositories from within either DevOps and here I go and choose the the repository I want to use for this demo which is this one here with this name so I copy its name then unlock for it right here copy the name I find the repository selected once I have to select the repository I still get the option to select a branch here because in some cases we might have like a master branch but also a dev branch and some other features branches and in each time we want to to mesh the feature and to the dev we need to pass through a pill request so agile devops here supports this scenario but here I continue with the master branch then hit continue and from now we'll start creating the CI pipeline here esra DevOps have two main options the first one will use the configuration as code this one uses the Yama files in order to define all the steps needed in order to run the CI and the CD pipeline's so we can put all this configuration into a ml file but every DevOps has another feature or another functionality which is defining those pipelines with visual tasks so I have a UI where it can see all the tasks that we will run inside my pipeline for that here those are for this second option I have many templates available here if I'm using a dotnet framework application then here I have a template for a dotnet application if I use an Android app here I have a template for that the same applies for if I'm using docker containers or if I have a Python application and even if I have a new GS application or iOS application or some marine applications in my case here I have a java application for that I'll go and choose maven some other people might want to choose Gradle to build their Android applications here I continue with maven so I select maven and click apply and here other DevOps generated a pipeline for me let's see what what is the content and the configuration for this pipeline so first of all we have the global configuration for the pipeline which here will specify the agent pool the agent here is the machine that will run my pipeline because we want to run the command maven clean package this command will run inside a virtual machine and it is the agent that will control the execution of the pipeline inside a virtual machine so from here we have different agents available we'll have we have agents that could run on Windows virtual machines or Linux or Mac OS while we have different ones for example if I have i io s application I need to have a Mac OS machine and if I have a dotnet framework application I need to have on those machines so we have this option for you but if you have the net core for example you can use any of those machines the same if you have a java application you can build it on Java on Windows Linux or or Mac OS here I'll go and choose hosted Ubuntu for example you see also here we have different versions for Windows machines we have ones that have Visual Studio 2015 and stylet or Visual Studio 2017 or 2019 and if you want to use on those containers then you have a virtual machine that have windows containers runtime and studied now we have configured the agent that will run the pipeline after that we need here from the parameters to specify the path for my poem XML file this file contains all the configuration needed for maven to build and run the unit tests and my java application so I can't go and click on this button here to access the repository for my application so I can access the same files that are on my application then I'd go and specify the path for my palm fire here it is inside my app folder and I go and select it boom dot XML so the path will be set to up slash bomb dot XML after that I have another section here for gate sources so this one will try to get the source code from github as we have already configured it then we'll start the running the job inside the agent so the agent here because we want to run or to build a java application using maven we need to make sure that maven is installed on the agent or on the virtual machine that's why we have here a section called demons so it will check if maven exists and my virtual machine if it doesn't exist it will tell me that this routine machine cannot run your pipeline so you need to choose another virtual machine after that here we have the main task that will run the command maven clean package which is here command called maven we have the name for this display command then we have the pawn file that we have configured it from the pipeline section then the goal here is to generate the package and then we have the option to to publish or to run tests using g-unit using maven so I'll do that then here other develops by default have created a test results file which will be an XML file that contains the the results for running the unit tests then I have some other configuration section for good coverage so here we can use either cobertura or J cocoa in order to run a good coverage for my app here I run cobertura for example we have some other available options like for do for specifying the Java home if you want to if you want to have some custom built environment so those are the main configuration I need to make so this task will run maven clean install or maven a clean package in order to generate the jar file and run the unit tests after that from the CD pipeline we'll need to get this jar file in order to deploy it and to your web app so to pass this jar file from the CI pipeline into the CD pipeline we need to put it inside a shared folder between the two which is called the artifact that's what we'll be doing by those following two tasks so first of all we'll take the jar file will copy it inside another folder and my local agent then I'll copy that jar file into the artifact that's the role of this publish build artifact task so this will take the content of the folder that contains my jar file then it will publish it into a drop folder inside the artifact so here I'm specifying the name it should be drop then here the the artifact the artifact here could be a file that or folder that will be saved by agile devops or you can also use a file another file share system so this is our CI pipeline now we are ready to run it so to start running this pipeline I'll go to this button save & DQ here I have the machine that they have specific then I click Save and view now agile devops started running this pipeline and here it gives me a link to follow the execution of this pipeline so I open that when the link in a new window and here I see that my pipeline started running so first of all it will provision an agent for me those agents runs on virtual machines on Azure so it will try to get a free agent for me it gets one then it will run or it will get the application source code from github for that here it will run the git checkout to get my master branch and that's what it is doing right here after that it will start running the task for maven and here it already started running maven clean install so from here we see the console window from the agent that is running my pipeline and we see here in real-time and within a few seconds the command where I run it and here it ran out the unit tests and it ran the tool to for the code coverage so now our pipeline did run in just one minute and 29 seconds if we go to this summary window here we can see a summary about the execution of the pipeline so we'll be able to see that we have inside our artifact folder we have the drop folder that we have created that we should that should contain the jar file so I go to view the content from here you should be able to see the jar file for my spring pod application but in addition to that it have generated another folder that contains the code coverage results so if I open this folder we can find here some HTML files that contains a summary about code coverage for my app because we have also run at some unit tests so we can see the results about running those unit tests so here we see that we have one unit test and it did run successfully so this is about our CI pipeline now let's go and start creating the CD pipeline from the CD pipeline what you want to do is to get that jar file from the artifact then deploy it into a web app inside Asia but first of all let's start creating a web app inside Asia that will host my Springwood application Here I am inside the edge reporter and they go and create a new resource I go to web and they'll start by choosing web app I give my application a name I call it a spring boot or Java spring boot then I'll choose to create a new resource group I select my subscription I use for a show then here I can use either or I can run my job application either inside Linux virtual machine in Asia or Windows virtual machine here I'll continue with Linux we can also deploy a container if you want then we have another configuration for the runtime stack here for algebra we have different versions so we can use 11 over Java 8 and we can also use Tomcat as an application server here I'll choose Java 8 using Java standard edition then I click create and here aja started provisioning web app for me so this will take just a few seconds then I'll be able to see my application running once the day web app was created I can click to go to see the resource and from here from within the overview window I can go to a click browse to open my web up in a new window and here you see the web app that we have created an azure for now it displays a default page configured by Asia which shows the Java version and some other information about my application now from the CD pipeline I want to deploy my java application and to this web app so that will should display the greetings from a spring boot I go back to either the verbs and here I go to the menu to select releases I'll open the releases window and a new window and my browser and here I click the button a new pipeline in order to create a new CI pipeline we have here different available options or templates to create a CD pipeline so depending on what type of app you have either the verbs I will give you a template to start creating your application so here we have templates for deploying Java applications and to Asia or deploying new GS applications or deploying into my my sequel or deploying a Python application we can also deploy and to kubernetes cluster because we have the right tasks for that and if used if you are using IAS and sequel a database sequel server then you have the right task to do that we have we can also deploy into service fabric we can deploy functions you can deploy go application we can use here and for deployment and so on so we have a large set of tasks available to support all your cases here I want to deploy into another app service so for that I choose this first task then I click apply after that here it asks for the name of my environment or my stage here I call this one my production once that's set now I go and add an artifact and the artifact here is the is the folder from where my CD pipeline will get its dependencies or the things it needs in order to deploy in my case I need to get the jar file so the jar file or the artifacts could be the output of Jenkins or the output of a team city it could be inside and measure or inside a docker registry like docker hub and it could be also a file from github here in my case it is the output of my build pipeline because it is there where we have deployed or published the jar violence and to the artifact so I'll select the build then here I need to specify which build I'm using here I only have one so I've selected then I click Add now from here my CD pipeline will get the jar file from this artifact and inside this CD pipeline I can click here to the to view the job and my CD pipeline will try to get the jar file and deploy it into a web app on asier for that it needs to connect to my ager account so from here I click this select here in order to specify which is your account I'm using here I have already connected to my account so that here I can see all the subscriptions I have and I choose the one which contains my web app then I go and authorize in order to let a sure DevOps connect to a sure REST API so it is almost the same thing that we have already did with github i specify my account my username once that's done now asier DevOps will be able to connect or to talk to either API so that it can get information about the the application that I have already deployed and to Asia once it is connected now I can go and fetch my either account to get the web app that runs on Linux because they have chosen my web app to run on Linux I select that then from AB service name I can click here to get all the web apps that runs on Linux inside my edger subscription and here I select the one that I have created for this demo Java spinning boot so this is the configuration to run this the CD pipeline now if I go to run an agent from here we'll be able to choose the agent that will run the CD pipeline here it could be different agents that runs the CI and CD pipeline it's it shouldn't be erased the same the same agent so here I would for example I'll choose hosted vs 2017 for this demo you can choose whatever agent you see here all of them they have the requirement in order to run this CD pipeline which should be the azure CLI it should be installed on that machine because it is the azure CLI that will try to connect your other subscription and deploy the application remember here always it is always the CI and CD pipelines are a set of commands and we need to always think about those required commands what we use it to do manually before running maven clean package or the other CLI commands under the deployed the application now they will be automated from Asia DevOps so this is the configuration we need to make now if I go to the task itself to the configuration of the task we can see that here it will connect to the other subscription that I have configured and master my environment it will connect to my web app that I have created then here it will go and look for the package that I want to deploy by default here it is configured to get the package inside a zip folder the but here I go and change that by clicking this button then I go and look for my jar file for that I go to inside the drop folder and from the target folder I go and select my jar file select ok so now we'll get this this path for this task we have some other available options we can for example I change the configuration settings this is useful if you want to change the connection strings used by your application so you can customize the to use some specific connection string for your dev environment and another one for your production environment for example so this is all the configuration needed in order to run or to deploy my application and to inertial observers you using Azure devoxx now we are ready to run this pipeline for that I go and hit save ok then I go and click the release button and create release then I go and create or I click the create button and here esra DevOps again gives me a link where I can follow the execution of my CD pipeline in real time so that it can see the logs coming from my the console of the agent here Ezra DevOps look at for an available agent it found one and now it is writing to connect that agent it will send the configuration for the CD pipeline into that agent so that agent could read that configuration and run it one by one and now here we get the output from the agent so it started by provisioning the agent downloading the artifact from or the jar file from the artifact then here it is also downloading the other files from the artifact then it started running the task for deploying and to app service what we are done successfully so now my web app is deployed and if I click on the deploy edge or AB service task we can see that here it tells me that it was successfully updated and my app was deployed and to this URL Java Springwood our websites but net which is the same URL we have uses here so now if I go to refresh this URL I should get my message greetings from Springwood so it was this simple to create CI CD pipelines for a java application using Azure DevOps to build the application and deploy it and to asia i want to show you another option here that we have and to create the SDI pipeline so if i go to try to create a new build i go and create a new build here will explore the first option that uses the Yammer configuration files the Yammer configuration files we use tools and as as part of the configuration as code so from there we'll be able to save all the configuration for the CI pipeline's so from here I can go look for let's specify a repository i specify the master branch and here from Yunel from here i'll be able to go to use the yama option for creating the pipeline for that here all we need to do is to specify the path for my amel file let's go and do that here my up you have already saw that they have created these as row pipelines that's a CI gamma if we go and take a look at the content of this file from here we could see that it is a Yama file and it contains the information about the configuration for the agent I want to use so here I tell it to use the Ubuntu agent then I have the configuration for my Yama or for my maven tasks so here I have the I the ID for the task then the path for my poem dot XML and then this task will understand that it should run the maven clean package then I specified the code coverage tool option here size map already specified cobertura and then the following two tasks I want to copy the files and to a local folder then we'll publish those local folder and to the drop inside artifact folder so this is the content for my Yama file I can use that same configuration here I specify it that ok then I go and save the configuration and now as you see here our DevOps starts I started running this pipeline and here I don't have any tasks as we have created before because the configuration for those tasks are now part of my gamified so all my configuration is inside the Yama file this is useful because I can go Miami file will be a version control it so it is it lives inside my Applications source code and here we can see the execution of this CI pipeline so we get the same execution and the same results as we did before here the V AMA file we use it here is the equivalent of zinc inspire if you are already familiar with Jenkins and we have many CI CD tools that support those files as part of configuration as code and from within some few seconds we'll be able to see our pipeline will run successfully another thing I want to showed you here is that in order to generate those are both Yammer files you have here the option of view Gamal so if I select my agent I go to view Yama I'll be able to see this pipeline exported and to a Yama file and here are the verbs can do that automatically for me so here I have the same contact for this geometry at the same content as I have used it and my repository I hope you found this tutorial useful and if you want to get more videos about Ezra DevOps and CI CD here I have and my youtube channel I have created some other videos about how to add your database to the CI CD pipelines how to run selenium UI tests how to use and how to deploy into kubernetes and so on so if you are interested go and subscribe to my youtube channel
Info
Channel: Houssem Dellai
Views: 36,501
Rating: undefined out of 5
Keywords: azure, devops, azure devops, ci, cd, continuous integration, continuous deployment, web app, java, springboot, web, maven, mvn, unit test
Id: QXIxKZINJV4
Channel Id: undefined
Length: 34min 46sec (2086 seconds)
Published: Mon Apr 08 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.