• Skip to main content
  • Skip to primary sidebar
BMA

BeMyAficionado

Inspire Affection

Jenkins Pipeline Script Should Not Contain Complex Logic

September 6, 2021 by varunshrivastava Leave a Comment

How are you doing it?

Do you have one big pipeline script with all sorts of logic that incorporate everything?

Or do you have a lean pipeline where a single stage does one and only one thing well?

I’ve seen many different ways in which companies organize their CI/CD pipelines. And it works for them. But there are a few designs that were really simple to understand and were highly flexible. Whenever I see a complex deployment pipeline that is hard to understand or have many components – I ask the same question – why didn’t they do it the other way – the simple way.

I feel that a new person should not take more than 15 minutes to understand your integration and deployment strategy after reading the Jenkins pipeline code. And if you have such a pipeline, then be proud of that.

Table of Contents

  • Things to consider
  • Lean And Simple
  • Easy To Debug
  • Flexible

Things to consider

There are 3 main things that I would consider if I have to create the pipeline from scratch.

  • Lean and Simple
  • Easy to Debug
  • Flexible

Lean And Simple

Typically in a project, we do the following,

  • we write code
  • we commit
  • every commit should trigger a build on that branch
  • and every build should be quick
  • after successful build run integration tests
  • deploy to stage (if required)
  • deploy to prod (if required)

If we have to translate these into stages of a pipeline then it would look like this,

Checkout
Build
Unit Tests
Integration Tests
Prepare Docker Image
Deploy On Staging
Deploy On Production

And the command that you write in every stage should be the same as what you will run in your local.

Sample commands for a typical java application for each stage would look something like this:

StageCommand
Checkoutgit checkout <commit> (probably use a gitscm plugin)
Build./gradlew clean build -x test
Unit Tests./gradlew tests
Integration Tests./gradlew integrationTests -x build
Prepare Docker Image./gradlew prepareImage
Staging Deploy./gradlew deployStaging
Production Deploy./gradlew deployProduction

One-liner.

This is the best. You wouldn’t want to increase any line of code there. No conditional nothing.

Your pipeline is to perform one task after another in the most reliable and efficient way. If you are writing logic into your stage then you are unnecessary increasing the complexity. Your pipeline is not built for handling logic it is built for managing different stages for your CI/CD workflows. So just use it for that.

You can optimize different stages to run in parallel as well which will save you a ton of time.

The fastest build-to-deploy time that I have seen for an enterprise application is close to 5 minutes. This is super awesome, given the fact that you built the artefact, published it, ran integration tests and then deployed the application. 5 minutes is super impressive. But a 10-minute pipeline wouldn’t be that bad depending on your architecture and code size.

The main time-consuming tasks are integration tests and deployments. Can’t do much about deployments but integration tests can be made super fast. Strive for that.

How much time does your pipeline take from build to deployment?

Easy To Debug

If you look at the pipeline then there are not many moving parts. So for any reason, if your pipeline doesn’t work, it is very simple to debug. Within 5 minutes you can pinpoint the problem.

First of all, a simple pipeline like the one I defined above wouldn’t face any problem in the first place. Even if it does, its super easy to debug.

So strive for that.

How quickly can you pinpoint problems in your pipeline?

Flexible

Flexibility comes when something changes in your system or practices. For example, your deployment strategy changed across the company for any reason. Then how quickly can you make those changes to be aligned with those changes?

Flexibility is very important. Usually, we don’t care for it while building something. And when something changes in the future, then the person responsible for it at that time will have to fix your doing. So, why not be sympathetic from the start and make everyone’s life easier.

How flexible is your pipeline to incorporate the change?

Let me know your views in the comments below.

Related

Filed Under: Programming Tagged With: jenkins, pipeline, programming

Primary Sidebar

Subscribe to Blog via Email

Do you enjoy the content? Feel free to leave your email with me to receive new content straight to your inbox. I'm an engineer, you can trust me :)

Join 874 other subscribers

Latest Podcasts

Recent Posts

  • Is The Cosmos a Vast Computation?
  • Building Semantic Search for E-commerce Using Product Embeddings and OpenSearch
  • Leader Election with ZooKeeper: Simplifying Distributed Systems Management
  • AWS Serverless Event Driven Data Ingestion from Multiple and Diverse Sources
  • A Step-by-Step Guide to Deploy a Static Website with CloudFront and S3 Using CDK Behind A Custom Domain

Recent Comments

  • Varun Shrivastava on Deploy Lambda Function and API Gateway With Terraform
  • Vaibhav Shrivastava on Deploy Lambda Function and API Gateway With Terraform
  • Varun Shrivastava on Should Girls Wear Short Clothes?
  • D on Should Girls Wear Short Clothes?
  • disqus_X5PikVsRAg on Basic Calculator Leetcode Problem Using Object-Oriented Programming In Java

Categories

  • Blogging
  • Cooking
  • Fashion
  • Finance & Money
  • Programming
  • Reviews
  • Software Quality Assurance
  • Technology
  • Travelling
  • Tutorials
  • Web Hosting
  • Wordpress N SEO

Archives

  • November 2024
  • September 2024
  • July 2024
  • April 2024
  • February 2024
  • November 2023
  • June 2023
  • May 2023
  • April 2023
  • August 2022
  • May 2022
  • April 2022
  • February 2022
  • January 2022
  • November 2021
  • September 2021
  • August 2021
  • June 2021
  • May 2021
  • April 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • February 2020
  • December 2019
  • November 2019
  • October 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • January 2019
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016

Tags

Affordable Hosting (4) algorithms (4) amazon (3) aoc-2020 (7) believe in yourself (4) best (4) database (4) earn money blogging (5) education (4) elementary sorting algorithms (4) experience (3) fashion (4) finance (6) Financial Freedom (7) food (7) friends (3) goals (5) google (5) india (10) indian cuisine (5) indian education system (4) java (16) life (16) life changing (4) love (4) make money (3) microservices (9) motivation (4) oops (4) podcast (6) poor education system (4) principles of microservices (5) problem-solving (7) programmer (5) programming (28) python (5) reality (3) seo (6) spring (3) success (10) success factor (4) technology (4) top 5 (7) typescript (3) wordpress (7)

Copyright © 2025 · Be My Aficionado · WordPress · Log in

Go to mobile version