Harshit Jain
CI/CD Task Using Jenkins
Overview
This document outlines the steps to set up and execute a simple CI/CD pipeline using
Jenkins. The pipeline demonstrates cloning a repository, running a batch file, and simulating
deployment.
What is CI/CD?
Continuous Integration (CI):
- Developers frequently merge code changes into a shared repository.
- Automated testing ensures early error detection and improved code quality.
Continuous Deployment (CD):
- Once CI tests pass, the code is automatically deployed to staging or production.
- Enhances reliability by reducing manual intervention and downtime.
Tools Used
1. CI Tool: Jenkins
2. Version Control: Git
3. Operating System: Windows (for running `.bat` scripts)
Task Workflow
1. Clone Repository: The pipeline pulls the latest code from a GitHub repository.
2. Run Script: A batch file (`.bat`) is executed as part of the build process.
3. Simulate Deployment: A deployment stage simulates application deployment.
Pipeline Script
Below is the Jenkins pipeline script used for this task:
pipeline {
agent any
stages {
stage('Clone Repository') {
steps {
echo 'Cloning repository...'
git branch: 'main', url: 'https://github.com/Harshitjain/Devops-Intern.git'
}
}
stage('Run Script') {
steps {
echo 'Running the script...'
bat 'trail.bat' // Execute the batch file
}
}
stage('Deploy') {
steps {
echo 'Deploying...'
echo 'This is a simple deployment simulation!'
}
}
}
post {
success {
echo 'Pipeline completed successfully!'
}
failure {
echo 'Pipeline failed!'
}
}
}
Execution Steps
1. Install Jenkins:
- Follow the steps to install Jenkins based on your operating system.
- Example commands for Linux (if applicable):
```bash
sudo apt update
sudo apt install openjdk-11-jdk -y
sudo apt install jenkins -y
sudo systemctl start jenkins
```
2. Set Up the Pipeline:
- Open Jenkins and create a new pipeline job.
- Paste the above pipeline script into the configuration.
3. Prepare the Repository:
- Ensure the GitHub repository contains the `trail.bat` file in the root or specified location.
4. Run the Pipeline:
- Trigger the pipeline.
- Confirm the following steps execute successfully:
- The repository is cloned.
- The batch script runs without errors.
- Deployment simulation completes.
Outcome
Demonstrated CI/CD basics with Jenkins:
1. Code cloning from GitHub.
2. Batch file execution (`trail.bat`).
3. Deployment simulation.
Provided a practical foundation for integrating CI/CD pipelines in development workflows.