I spent much of my formative years in High School and College being indoctrinated with Object-Orientated Programming (OOP). When used well, OOP provides clear modular structure for programs, defines clear interfaces, makes software easier to maintain and modify, allows multiple functions to share code (cord re-use), and reduces large, complex issues to smaller, more manageable ones. When it comes to doing DevOps, I have seen a tendency to create specific jobs for specific tasks and very few professionals applying OOP to how they build and deploy software.
So when it came to my current project, I set out to do that just.
On my current engagement, we are utilizing Jenkins to perform build tasks, deployments and operational tasks for hundreds of servers across multiple environments. My client spent months attempting to build out a CI/CD infrastructure and build jobs with little success. Their jobs were haphazard and un-maintainable at best. Due to policy and system architecture, each environment contains it’s own Jenkins server that do not communicate with one another. Couple a vary large (and ever growing) network with a rapidly changing code base for multiple applications that may share some common code and resources, this project lends itself to jobs built with OOP in mine.
So how do you go about building a reusable job? Let’s start by installing a few plugins to help us out.
We are going to need to be able to pass in a set of variables for our jobs and there are a few plugins that will help us do just that. Start by downloading the Parameterized Build plugin for Jenkins.
- Login to Jenkins
- Click Manage Jenkins
- Click Manage Plugins
- Select the Available Tab
- Find the Parameterized Build Plugin and select the check box next to the plugin
- Click the Download now and install after restart button at the bottom of the screen
For your project, you may also find the Build with Parameters Plugin and the Parameterized Trigger Plugin although I won’t be covering them in this blog post.
Creating Your First Parameterized Job
Making your own parameterized build job is as simple as creating a new job. Click New Job and you will see a new kind of job called ‘Build Flow‘. Select the Build Flow option and now you only have to program the job using the flow DSL.
Under the Build Triggers section you will find a section to input the build flow DSL.