Overview of Pipeline as Code
A free video tutorial from DevOps Training
4.2 instructor rating • 2 courses • 15,064 students
Learn more from the full courseLearn Jenkins from a DevOps Guru
Learn how to build automated continuous integration pipeline with Jenkins. Take your DevOps skills to the next level.
03:46:50 of on-demand video • Updated February 2019
- Understand the concepts of continuous inspection, continuous integration, and continuous deployment, and the difference between them.
- Implent an automated continuous integration pipeline to build, test, analyze and deploy a web-based application with Jenkins.
- Create a multi-stage Jenkins job and visualize the complicated build pipeline with Jenkins build pipeline plugin.
- Integrate continuous integration builds with other tools such as Java, GitHub, Maven and Tomcat in a more comprehensive software delivery strategy.
- Scale Jenkins workflow with Jenkins’ master and slave architecture, deploy and configure a multi-node Jenkins cluster in the cloud for labeled builds.
- Learn how to configure and extend Jenkins functionality with Jenkins plugins such as copy build artifacts plugins and deploy to container plugins, etc.
- Invaluable DevOps skills such as setting up staging and production environment for continuous integration workflows.
- Best practices of working with Jenkins in the field.
- In-depth knowledge about Jenkins and confidence to help your company or your own project to apply the right Jenkins workflow and continuously deliver better software.
English [Auto] Hey guys. Welcome back. My name is galas and I'm a natively us and Google certified cloud engineer. I use Jenkins on a daily basis in my job and I think it's an amazing tool that has pushed dev ops to the forefront of our careers. In this lecture we're gonna start with a simple example. So feel free to sit back and just watch. But in the following lecture I'll ask you to follow along as we convert our current web application pipeline into code. Let's begin pipeline this code is a very convenient way to define and maintain your Jenkins pipeline. It uses a DSL or domain specific language to allow you to define tasks that you want Jenkins to perform. And the best part is you get to include your Jenkins specific commands in the repository itself. It lives for your code lives. But I'm getting ahead of myself here. We're going to start off discussing why you need it all the benefits that you get from it and then we'll set it up and I'll show you a simple example in the next lecture we'll go deeper and we will convert our current pipeline into code that's going to be included in what projects get our repository and Jenkins we'll take it from there. Let's get started. So as we said in the previous slide a Jenkins pipeline can be defined in a text file. Call a Jenkins file that you include in the root of your repo. This is very useful if your company has many many Jenkins jobs to keep track of because now you have all the benefits of sulphur development available to your pipeline version control is one of those. And thanks to branches and pull requests others get a chance to review the changes before the pipeline is actually change usually when you execute a series of jobs manually in Jenkins. You run the risk of forgetting something with a coal based pipeline. This is no longer an issue. You also have access to performing actions automatically based on time outs failure or success of the steps of your job. Of course you could do all this manually in the Jenkins web interface but it's so much more convenient. Would you just add a few commands put him in a version control file and they stay there forever as part of your project. Before we proceed with our simple demonstration let's take a look at what a Jenkins file looked like. By the way if you want proper syntax highlighting when working with these files send your co editor to groovy. In case you don't know. Groovy is a Java based scripting language and it's the backbone that validate and execute your Jenkins file because this is a lengthy topic we can't possibly cover every feature that is available to you in the Jenkins file but we will provide you with links to reference material you'll be working most of the time within the scope of the stages keyword you'll be the finding and specific stages and within those stages you'll be the finding the specific steps in our example the initialized stage has one step which is a shell execute step that prints to environment variables to the screen the bill stage has one step and it just brings to Hello world message before we do an actual useful example let's go to the Jenkins console and we'll define the Jenkins job that will execute this pipeline and then we get to see what it looks like. Let's go Okay guys. Here we are in the Jenkins console as you can see I don't have any jobs defined at the moment. Before we proceed with any sort of job definition I would like to go ahead and make sure you have what we need to proceed. So we'll go to manage Jenkins and then we'll proceed to manage plugins. If you see I have I'll go down here to the letter P. scrolling. OK here I have a pipeline that's the plug in or I should say a suite of plugins that lets you orchestrate automate simple or complex tasks see pipeline as code or a junket for Modi. Version 2.5 if you have that under your install tab you're good to go. If not no big deal. Just go to available plugins type pipeline here and then you'll be able to proceed to install and then restart to Jenkins and you'll be good to go so anyway back to the dashboard here. So what we're gonna do is gonna create a new job. And in this case we're gonna tell Jenkins Hey you're gonna pick up your commands from a Jenkins files and you're gonna pick up your code from a certain repository now think about the possibilities that you could hook up Jenkins that it will detect every time you commit changes to your repo and then you would never ever have to come to this UI because your pipeline will be a code file. OK. So for our example what we're gonna do is we're going to create a new job we're going to define it as a pipeline with a type of name here. We're going to call it pipeline as code example. Define this pipeline and click OK and here at the bottom where it says pipeline script of course I'm not going to type it in here. I'm gonna say take it directly from source code management and that SVM is going to be get I'm gonna paste here the URL where our repo doesn't require any credentials and we're gonna use the master branch and the file is gonna be Jenkins files and it's gonna be in the root of the repo and that's it. I'm just going to click save if I go back to the dashboard. I have this defined already I could run it and if I run it it's going to go to the repository who's going to pick up the code as well as the Jenkins file as gonna execute whatever commands are in the Jenkins file. Let's go have a look at that. This is the repo and I'm using our own example web application that we've been using all along in this and this course. Now I just added a Jenkins file here. This is very similar to the one we just saw in the PowerPoint presentation. I just added three stages in it. Build and deploy. In this case they don't do anything useful. It just outputs three messages testing building and code deployed. So again this isn't anything useful for the moment but it will allow us to see and configure properly our code pipeline and then we can come back. Edit this file on an actual building steps. Let's go back to Jenkins. We're going to try and execute our pipeline now and see what happens. This bill schedule as you can see is running right away and a completed perfect. Let's go into the job now. The first thing you'll notice here is that it chose in it built and deploy. If we go back to our code editor here you will see that it says in it built and deployed those sort of three stages that we define if we click our specific built number here built number 1 and click console output go all the way to the bottom. You'll be able to see our messages here and finish with success great. Our pipeline works now while we need to do is at actual useful steps that will pick up the code trigger and may them build and do an actual deploy to our TOMCAT server before we end this lecture I wanted to point out what we just saw even though it was very very simple. We have three stages that we just defined in our Jenkins file and if we go back here to the job that we configure all we really did was to define which repo we're going to use and then we tell it to use a Jenkins file. We did nothing else this reduces the number of times you're ever going to need to be inside your Jenkins web interface. You no longer need to leave your code editor to manage your pipeline. All you need to do is come here changed your Jenkins file at steps or remove steps as needed. Major changes and that's it. You're good to go as you know right now. Our pipeline doesn't do much other than print messages. So in the next lecture we're going to make it more complex and we're gonna actually use maven to bill our project and deploy to our tomcat. Let's go.