From Basics to Pipelines

neha chaturvedineha chaturvedi
2 min read

Building Your First Jenkins CI/CD Workflow

In the previous post, we explored Jenkins fundamentals—installing the server, creating jobs, and setting up basic plugins. Now, let’s go deeper. This post will help you build your first real-world CI/CD pipeline using a Jenkinsfile, version control, and automated test/deploy steps.


🧱 Why Use Pipelines?

While freestyle jobs are great for beginners, pipelines offer:

  • Better reproducibility (code as configuration)

  • Easy rollback/versioning

  • Flexibility and scalability

Pipelines are defined using a Jenkinsfile, usually stored in your Git repo.


🛠️ Step-by-Step: Create a Simple Jenkins Pipeline

1. Create a GitHub Repo

Add a basic Node.js or Python app with a Jenkinsfile in the root.

Example Jenkinsfile:

groovyCopyEditpipeline {
    agent any
    stages {
        stage('Clone') {
            steps {
                git 'https://github.com/your-username/your-repo'
            }
        }
        stage('Build') {
            steps {
                sh 'npm install' // or pip, Maven, etc.
            }
        }
        stage('Test') {
            steps {
                sh 'npm test' // use your test command
            }
        }
    }
}

2. Create a Pipeline Job in Jenkins

  • Go to Jenkins → New Item → "Pipeline"

  • Set SCM to Git and provide the repo URL

  • Jenkins will automatically detect the Jenkinsfile


🔐 Pro Tips for Smooth CI/CD

  • Use environment variables to secure secrets

  • Add post actions for notifications (Slack, Email)

  • Use parallel stages for faster test execution

  • Use Blue Ocean plugin for a modern UI


🧠 What’s Next?

In the next blog, we’ll cover:

  • Deploying to a staging environment (e.g., Docker, Kubernetes)

  • Advanced pipeline syntax (shared libraries, input steps)

  • Integrating with tools like SonarQube and Nexus

0
Subscribe to my newsletter

Read articles from neha chaturvedi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

neha chaturvedi
neha chaturvedi