Introduction: How To Configure CI/CD Pipelines in GitLab
Hello and welcome to how to configure your first GitLab CI/CD pipeline. My name is Michael Roberts, I’m the vice president of sales and marketing here at SPK and Associates and I’m here today with. Darla Kost. Darla, feel free to introduce yourself.
Hi everyone. I’m a DevOps engineer over at SPK and Associates as well. Going to be walking you guys through a really simple how to create your first pipeline in GitLab.
Philosophy: Pipeline as Code
So today we’re going to try to give you some of the basics about GitLab’s CI/CD feature. So, how does GitLab CI/CD philosophy underpin the idea of a pipeline as code approach? And why is defining your pipeline in that GitLab CI YAML file so transformative compared to traditional ways of doing like manual builds?
Well, GitLab has a really cool philosophy that your CI/CD pipeline should live alongside your code. It should be versioned. It should be reproducible just like your application is. So, if you go ahead and you define your workflow in that YAML file, you replace all those manual ad hoc builds with something that’s really predictable, an automated process that anybody on your team can see, they can edit, they can audit over time. It’s a really good shift from, you know, those one-off scripts or clicking buttons in a GUI, and that just makes every change to the build and the deploy process like it’s tracked, it’s testable, repeatable, all those things that you need for good collaboration.
Common Mistakes in Structuring Pipelines
So, from your experience, what are the most common mistakes that teams make when structuring that CI/CD stage in a in a GitLab, build, test, deploy, naming convention and how do they how do they get better at that? Like, what are the things that they need to be aware of?
Oo, there’s a couple that seem to reoccur. One is definitely cramming way too many tasks into one single stage or job. I’m going to show you what those are in a second, but it just makes troubleshooting a lot harder. It definitely slows down any kind of feedback.
Another one is probably using, you know, if you’re not using really clear or really descriptive names for your stages or jobs, it makes it really hard to follow for new developers. So, you know, for best results, I’m always saying, you know, keep stages focused. Your build, test, deploy should have really clear purposes, titles. Make sure you parallelize when you can. So, you know, use keywords to let your jobs run concurrently. And definitely define explicit dependencies. So, don’t rely on those default stage orders if those jobs really depend on each other. Use actual dependencies or needs to make it clear.
Example: GitLab CI/CD Pipeline Configuration
Gotcha. So, I’m going to let you share and walk through. Could you walk through a basic YAML file example? Maybe give a three-stage deployment featuring build, test, and deploy, and maybe explain each component so that people can understand how that runs through GitLab.
Definitely. So, I’m going to go ahead and pull that up really quickly. Okay. Can you see? I gotcha. Okay. Awesome.
YAML File Setup and Stages
So, this is basically a new file in this vlog demo project that I created in GitLab. So, this is the GitLab CI.L. All I did is go to create a new file. Went in here and created this name. Once you populate this name, it’s going to automatically create it for you. And then I went in here, and I have these stages. As you can see, there’s a build, test, deploy stage. Each of these top-level keys is an actual job, and then each job is going to belong to a stage.
So in this case, all we’re doing is creating, you know, a text file. But right here, this is the build job. So we’re going to go ahead and build what we’re trying to do. So this is going to be compiling whatever your application would be, you know, making your directories or making your projects, whatever it is you need to do. And then that’s going to go ahead and complete the build section.
And then we’re going to go to our test job section, which is also clearly labeled. If there haven’t been any tests or anything that you’re going to run, you’re going to run them right here. In our case, we’re just going to have a little fake test that’s going to run our application, our text file.
Deploying The File
And then your last stage is going to be deploy. So as you can see, that’s also really clearly defined. And this is where your actual deployment steps would be. In this case, we’re not going to deploy anything. We’re just going to cat the file that we just created. But GitLab will read this file, and it’ll orchestrate the entire thing automatically. So, it’s going to compile, it’s going to test, and then it’s going to deploy. If any of the jobs here fail, later jobs are going to be skipped. So, you know, you can’t have a failed build and then it automatically runs over to tests or deploys or anything like that. That’s going to ensure your quality at every step. And you can also visualize this really easily in the pipeline view, and that’s going to make things a lot easier for people when they are trying to develop.
Commit and Run
So I’m going to just go ahead and I’m going to hit commit changes here, and it’s going to commit to the main branch, which is what we’re going to do right now. And then we are good to go. Okay. So this is going to show us what we would do to actually run the pipeline. So as you can see, it’s building. It’s going to go ahead, and it’s going to run through test and deploy. Hopefully it runs through. Had a bit of a technical snafu verifying my account. So then, if you go in here, you can actually see everything going through. So we can see the job succeeded right there.
Live Status and Visualization
She’s still running. And then you can also check your stages right here. So each stage is going to come up as a different little bubble. And then if you hover over it, you can actually see it go ahead and through and pass.
Edit and Simplify
Maybe it’s mad at me. Let’s go ahead and edit this.
Let’s simplify it. I guess we can go ahead and push.
There we go. We love green check marks. Maybe check.
All right. So, there we go. We have all three check marks that are green, which means all three of our stages are passed. We did have to cut out a very small thing just to make this as simple as possible, so that we could run it through on our demo instance. But that is pretty much how you do it. Easy peasy.
Implementing a GitLab CI/CD Pipeline Configuration
And yeah, thanks. That was great. Hopefully, you’re learning from this video. So, thanks for joining us and hopefully, you’ve got your first GitLab CI/CD pipeline build in place. And as demonstrated, adopting that pipeline as code approach in GitLab not only streamlines the development workflow but also kind of lays the foundation for greater automation, repeatability, and collaboration too. So don’t forget to like this video, subscribe to the SPK and Associates YouTube channel to check out other videos about more practical tips from the engineering and software teams, including GitLab. Until next time, thank you. Appreciate it. Thanks, guys.