Jenkins-NodeJs-do-app-cicd
2 min readApr 3, 2024
Prerequisites:
- Jenkins Server: Ensure you have Jenkins installed and running. If not, you can install Jenkins following the official documentation.
- Docker: Make sure Docker is installed on the Jenkins server, as we’ll be using Docker commands in the pipeline.
Steps:
1. Fork and Clone the Repository
- Fork the To-do-app-cicd repository to your GitHub account.
- Clone the forked repository to your local machine.
2. Create Jenkins Pipeline
- In Jenkins, go to “New Item” to create a new Pipeline.
- Enter a name for your pipeline (e.g., “TodoAppPipeline”) and select “Pipeline” as the type.
- Click “OK” to create the pipeline.
3. Configure Pipeline Script
- In the pipeline configuration, scroll down to the “Pipeline” section.
- Select “Pipeline script” as the Definition.
- Copy and paste the following script into the Script box:
pipeline {
agent any
stages {
stage('Clone Repository') {
steps {
git 'https://github.com/your-username/To-do-app-cicd.git'
}
}
stage('Build Docker Image') {
steps {
script {
docker.build('todo-app', '-f Dockerfile .')
}
}
}
stage('Deploy to Jenkins') {
steps {
script {
docker.image('todo-app').withRun('-p 8080:8080 --name todo-app') { c ->
echo "App running on http://localhost:8080/"
}
}
}
}
} post {
success {
echo 'Pipeline succeeded!'
}
failure {
echo 'Pipeline failed :('
}
}
}
4. Save and Apply Changes
- Save the pipeline script.
- Click “Apply” and then “Save” to save the pipeline configuration.
5. Run the Pipeline
- Go back to the Jenkins dashboard and find your newly created pipeline.
- Click “Build Now” to run the pipeline.
- Jenkins will clone the repository, build the Docker image using the Dockerfile in the repository, and deploy the application to Jenkins itself.
6. Access the Deployed Application
- Once the pipeline completes successfully, you can access the deployed application on Jenkins.
- Open a web browser and navigate to
http://jenkins-server-ip:8080
to see the deployed Node.js Todo App
If you like feelfree to connect us.#Authomation_enthusiast.