How to Setup CI/CD Pipeline?

How to Setup CI/CD Pipeline? : CI/CD pipelines: automate development and deployment processes efficiently.

Written by: storytechs.com

l

April 25, 2024

Chapter-17 << Chapter-18 >> Chapter-19

How to Setup CI/CD Pipeline?

Let’s Get Rolling: Setting Up My CI/CD Pipelines

Hey there, fellow tech adventurers! Today, I’m embarking on a journey to set up my very own CI/CD pipelines. If you’re like me, you’ve heard all the buzz about Continuous Integration and Continuous Deployment (CI/CD), but diving into the nitty-gritty can feel like stepping into a labyrinth. Fear not! I’m here to guide you through the process with a sprinkle of enthusiasm and a dash of tech magic.

The Setup: What You’ll Need

Before we dive headfirst into setting up CI/CD pipelines, let’s gather our tools:

Version Control System (VCS)

I’ve opted for Git, the Swiss Army knife of version control systems. It keeps my code organized and allows for seamless collaboration with my team.

CI/CD Service

There are plenty of options out there, but I’ve decided to go with Jenkins for its flexibility and robust feature set. Plus, it’s open source—perfect for a budget-conscious software professional like me.

Deployment Target

Whether it’s a cloud platform like AWS or a self-hosted server, I’ve chosen where my code will be deployed after passing through the CI/CD pipeline.

Step 1: Setting Up Jenkins

Now that we have our tools ready, let’s dive into the setup process:

  • Installation: I head over to the Jenkins website and follow the installation instructions for my operating system. A few clicks later, and Jenkins is up and running on my machine.
  • Initial Configuration: After logging in to Jenkins for the first time, I configure basic settings like setting up a new user account and selecting plugins to install. Jenkins offers a plethora of plugins to customize the CI/CD pipeline according to my needs.
  • Creating a New Pipeline: With Jenkins ready to roll, I create a new pipeline project. I choose the “Pipeline” option and configure it to pull code from my Git repository.

Step 2: Writing the Pipeline Script

Now comes the fun part—writing the script that defines my CI/CD pipeline:

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                // This stage builds the project
                sh 'npm install'
                sh 'npm run build'
            }
        }
        stage('Test') {
            steps {
                // This stage runs automated tests
                sh 'npm test'
            }
        }
        stage('Deploy') {
            steps {
                // This stage deploys the code to the server
                sh 'rsync -avz --delete dist/ user@myserver:/var/www/html'
            }
        }
    }
}

In this script:

  • The `Build` stage installs dependencies and builds the project.
  • The `Test` stage runs automated tests to ensure everything is working as expected.
  • The `Deploy` stage deploys the code to my server using rsync.

Step 3: Testing the Pipeline

With the pipeline script in place, it’s time to put it to the test:

  • Pushing Code Changes: I make some changes to my code and push them to my Git repository.
  • Watching Jenkins Work Its Magic: As soon as Jenkins detects the code changes, it kicks off the CI/CD pipeline. I sit back and watch as Jenkins builds, tests, and deploys my code automatically.
  • Checking the Results: Once the pipeline is complete, I visit my deployed application to ensure that everything went smoothly. Thanks to CI/CD, my changes are live in no time!

Step 4: Iterating and Improving

Setting up CI/CD pipelines is just the beginning. As I continue to develop and refine my application, I’ll iterate on my pipeline, adding new stages, improving testing processes, and automating even more tasks. With CI/CD, the sky’s the limit!

Wrapping Up

And there you have it—my journey to setting up CI/CD pipelines! While the process may seem daunting at first, with the right tools and a bit of perseverance, you too can harness the power of continuous integration and deployment. So, what are you waiting for? Let’s automate away and make software development a breeze! 🚀

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *