Scripting your own Pipeline (as Code)
The image is licensed under the Creative Commons Attribution-ShareAlike 4.0 license.

Scripting your own Pipeline (as Code)

How many times have you heard "This will take a lot of time to implement in the CI/CD pipeline? Do you even know how difficult it is to change a operational CI/CD pipeline? We cant afford a change in the CI/CD pipeline right now."

I heard it a lot and always felt curious to see what is behind the CI/CD pipeline and reason out the tedious scripts written behind them until last year when I first started evaluating the Pipeline as Code option available in Jenkins. Now I do not bother to look into any scripts, I just write them on my own.

I use a scripted pipeline, all my projects have a Jenkinsfile in the root. You can refer the official documentation here for details. I will give you some insights to writing up a good Jenkinsfile.

When you think about CI/CD the basic requirement will be to,

  • Checkout the source code from the repository.
  • Build your deployment artifacts.
  • Store the artifact in an artifactory.
  • Generate deployment files.
  • Finally deploy to the runtime environment.
  • Archive the workspace artifacts.

There would be other stuff like quality, security and storing deployment logs but we will first focus on the basics here.

If you have read my first article you would have noticed a Dockerfile in the repo. I use docker to build my images. On the same context, I use a file called as Jenkinsfile in my repo which describes the stages for the pipeline.

To start with just to get familiar with the syntax. You will notice a node at the root and stages within the node. To keep it simple I will use a single node for the entire process. I would also suggest you to get Groovy 'ing a bit

node {

stage('greetings') {

sh 'echo "Godspeed"'

}

}

The basic flow would be to,

checkoutFromGit > build > lint > audit > test > pushToRegistry > deploy

A sample Jenkinsfile here demonstrates the stages mentioned above.

The advantages of having a scripted pipeline is that you can move to any jenkins setup anytime you want. It gives you the flexibility to move away from tedious configurations and scripting required to manage the pipeline.

A couple of plugins to look out for are blue-ocean, credentials, sonarQube and slack.

Disclaimer: the views and opinions expressed above are solely derived from my personal experiences and does not represent my employers or anyone else’s.



To view or add a comment, sign in

More articles by Mrityunjay Mukherjee

  • The One Where the Developer Became an AI Product Engineer

    Something has quietly shifted in how I write software <articles as well>, and I suspect it's shifted for many of you…

    1 Comment
  • The one with security on my mind

    I have been trying to write something around secure coding for quite sometime now, though I am not a cyber security…

    1 Comment
  • Code for Humans

    I have been studying on the topic of writing better code for a few months now and have attended some workshops/sessions…

    7 Comments
  • Service... Stay in your limits please (pun intended)

    I have recently been talking to multiple teams about the right way to do microservices. You might think that I know it…

  • Setting up NGINX Ingress Controller for kubernetes

    So you have written a microservice and now want to run it on kubernetes or you just want to understand the way to setup…

    1 Comment
  • KEEP CALM & run Node.js

    Hope my last article was informative and helped you guys gain some insights on using Node.js for your developments.

    2 Comments
  • Is Node.js production grade?

    Over the last year and a half or so when we started our journey into the world of microservices based, cloud native…

    2 Comments

Others also viewed

Explore content categories