How to Use the Warnings Next Generation Plugin in Jenkins

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we're going to talk about how to use the warnings next generation plugin in jenkins [Music] are you new here if you are welcome and if you are new here you don't know who i am my name is darren pope and i'm a developer advocate for cloudbees as an application developer you might be using tools such as find bugs pmd check style there's numerous static analysis tools that are available for you within a java ecosystem or in numerous other languages however previous to warnings next generation you would have to install separate plugins for each of these tools in order to get visualizations for what happened within that tool warnings next generation gives you the ability to aggregate all of those visualizations under one umbrella here's our starting point for today i have a jenkins controller version 2.277.3 to it i have an agent connected to it with the label of linux we're going to work our way through an example here so hang out with me here for a few minutes we're going to start with a multi-branch example so i'm going to click on new item and then i'm using multi-branch sample app we've used this before if you haven't seen the videos before that uses this that's okay we're starting from scratch you'll be able to follow right along got a multi-branch and let me grab my branch source and get okay and now let's go ahead and click on save now as it scans the repository it's going to find numerous branches the one that we're going to focus on first will be our main branch so you can see we actually have a main and a warnings in g at the moment this jenkins controller does not have the warnings in g plugin installed let's go ahead and go take a look at the repository i'm on the main branch and within my jenkins file i have just a single stage i'm doing a gradle w clean check no daemon and then i'm calling junit in my post always so no matter what happens this is the command that's going to run on my main branch so now we're on our main branch let's take a look at what happened here so we ran our gradle clean check command we had a failure with one of our tests because i have a failing test within the job and then it recorded the test results because that was the junit step so if we take a look at the detail page for one we can see that the test results are right here and this is just the junit representation this is just classical junit within a pipeline so i had a failed test i expected faults but it was true it's just a contrived example because i wanted a failing test there's one passing test as we can see represented within the blue with two tests and we had one failure so i'm okay with this but i also want to add to this job the ability to run check style so how do we do that let's go back over to our repository and let's flip over to our warnings in g branch and before we take a look at the jenkins file i want you to take a look at bill gradle now whether you're using gradle or maven or node your your tooling is going to be different but in my case i added check style to my build.gradle file and that's the only thing i had to do in order to make check style available to me so now let's take a look at our jenkins file so everything is exactly the same up through the point of j unit but we added this one step for record issues record issues is the step from the warnings next generation or the warnings in g plugin so we can see here that we're going to use some java tools check style and i give it the location of where the output of the check style report is and then just report encoding again i'm only using check style extra well and java if you want to be technical but check style is the one that i'm targeting for this run now if we go take a look over at our job as it exists if we go to warnings in g we see this one also failed and the reason why this one failed if we get all the way down to it is we actually have bad code in here so it's not even able to compile instead of it being a return it's a returns so i messed up i have bad code in my repository and we can also see here that there's no such dsl method let's take a few moments and get our jeekins controller set up so we can actually run with the warnings next generation plug-in so how do we do that well we need to install a plugin so let's go to dashboard manage jenkins manage plugins we'll go to available i'm going to type warnings and you will find warnings next generation at the time of recording the current version is 9.0.1 i'm going to check this box i'm going to download now and install without restarting now what you'll see here is warnings next generation pulls in a couple of other plugins there's an analysis model there's a forensics and a data tables api so these are all required dependencies for warnings next generation let's go ahead and do a restart while we are waiting on that restart to complete let's take a look at the plugin page for warnings next generation you can see here at the very top it collects compiler warnings or issues reported by static analysis tools this is a key part it collects warnings or issues it does not actually do the analysis so if you want to be able to have check style results you actually have to have check style available to you to run that's what we'll see in a few moments the other thing to recognize here and i mentioned it earlier is the one the next generation warnings plug-in replaces the whole jenkins static analysis suite in other words it makes the following plugin plugins obsolete android lint check style find bugs all of these these are all now no longer necessary because of the existence of warnings next generation and again just to reiterate this plugin does not do the static analysis for you it just visualizes the output of those tools before we get started again looking at our controller let's dip our jenkins file between the main branch and our warnings in g branch and you can see here the only thing that we've added is the record issues step okay let's go ahead and head back to our controller which is right there and let's log in let's go ahead and go run our warnings in g and let's see what happens here again go to multi-branch we'll go to warnings in g and let's do a build now so the only thing that we've done is installed the warnings next generation plug-in and its dependencies see what happens so we're running our gradle clean check there's our java compiler checks for record issues and also our check style from record issues java compiler is java check style is check style okay now let's go and take a look at the output from warnings in g so we clicked on the detail page in my case for number two and we can see here that the static analysis shows two warnings and there's also this triangle we'll come back and look at the info after a while but let's click on two warnings you can see that we have two errors we have a donut chart here and we go to issues so we have details of this these are the issues i have hello controller 11. it says returns is not a statement well we already know that that just means i was fast and committed and didn't even bother to test it locally we can also see that we also have another one here that from a java perspective it's like hey you're missing a semicolon actually the semicolon is there it's just because of returns is failing out so this one is sort of a red herring so i'm not as concerned about this one but from a static analysis perspective it is a legitimate error at this point so let's go ahead and fix our hello controller problem so i'll do source main java hello control oops.com and now hello controller and let's fix the returns and turn it into return okay so there's that git add dot whoops get add and dot all right and get commit dash m and we're going to say fix hello controller and now i'm going to do a get push okay so now we've made that change up to our warnings in g branch let's go validate that real quick just to make sure we didn't do something silly it's always possible when you're doing things live so source main java hello controller and now it's just return hey now that we've fixed our repository let's go and run the job again go back to warnings in g let's do a build now as it gets started what we'll see here is another clean check again nothing has changed in our jenkins file and now we had another failure which we know about because we do have a failing test but let's take a look at the output on three previously from a static analysis point we only had two warnings well now we have actually had two errors not warnings now we have six warnings no errors that's good we have static analysis results from check style and the java compiler and also notice this information we'll come back and look at that in just a second let's take a look at our warnings again everything donuts fine the trend line is moving up now instead of issues we have files categories types and issues if we were to click on to demo application we can look at our checks design javadoc and white space let's click on checks and we can click into that and it says the parameter args should be final okay well thanks that's pretty cool let's take another look here at design we take a look there we can see that utility classes should not have a public or default constructor okay that's great and we'll just take a look at whitespace because everybody writes javadocs right and we take one more look here file contains tab characters this is the first instance tabs versus spaces your choice this is where you would define your check style xml file for what rules you want to actually test with let's go back over here one more time and take a look at categories we can also see here that we actually have two design issues so the way to think about this is we have files and we can drill into a file and then look at what categories are within the file this other tab starts with categories and then we can drill to files we also have types which are the types from in this case check style and then any issues that we have we can see these as well with their categories javadoc design white space all of this visualization makes it easier for you to track down what is going on in your code in case it's a compile issue we took care of our compile issue but now it's a check style issue for us these are the corporate standards that we want to enforce this is giving us an easier visualization to be able to track down those changes that we are going to need to make do you remember that information bubble that we saw let's go back over to this so go back to number three let's click on this information bubble this is the place if there's any information messages around warnings next generation that you may need to deal with in this case it's informational but you could also have errors but i want to call out one thing the information gives us if you look down here you can see that we have a line here called creating sem blamer to obtain author and commit information for affected files there's no blamer installed yet you need to install the git forensics plugin to enable blaming for get well that sounds like a good idea i want to be able to blame whoever the developer is even though it's me sort of makes sense so going through and understanding what's happening within this informational or warnings depending on what the scenario is at your time gives you the ability to dig through and figure out how to potentially make this even better and more useful so let's go in and install the get forensics plugin so again we'll head back up to dashboard manage jenkins manage plugin available and get forensics we'll do that download now and install after restart and once it switches over here we will do our restart okay now we're back so let's go ahead and log back in and let's go run our job one more time we're going to multi-branch we'll go to our warnings in g branch let's click on build now let's follow this along this time we can see here that everything is completed let's go back over into number four we still have six warnings but you'll notice one thing here we now have the scm block showing up and it gives us the initial recording of 73 commits the latest commit is this git hash let's go into our warnings because what you're going to see here now is we now have an scm blames tab that we can look at and we can say that oh we can blame this one on darren because he wrote this one we can blame this one on durham because he wrote this one and you can look and see which commit that change went into that's pretty quick look at warnings in g or warnings next generation whichever you prefer if you don't have a standalone service or tool that gives you the ability to visualize all of the information that's available to you consider installing the warnings next generation plugin it will help you in making your code that much better now if for some reason a tool that you're using is not supported by warnings in g you can either define a new groovy based parser or you can provide a parser through a new small plugin if you have any questions or comments you can reach out to us on twitter at cloudbeesdevs this video was helpful to you give us a thumbs up and if you haven't subscribed to cloudbeestv yet why not take a moment click on that subscribe button and then ring that bell and you'll be notified anytime there is new content available on cloudbees tv thanks for watching and we will see you in the next video you
Info
Channel: CloudBeesTV
Views: 1,381
Rating: undefined out of 5
Keywords: darin pope, jenkins, jenkins tutorial, jenkins pipeline, warnings next generation, warnings next generation jenkinsfile example, warnings next generation pipeline example, static analysis jenkins, static analysis, continuous integration, continuous delivery
Id: tj3xYFA6Q2o
Channel Id: undefined
Length: 17min 8sec (1028 seconds)
Published: Thu May 06 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.