Introduction :
Prerequisite:
Set up Ec2 instance.
Install Docker & Jenkins
Add permissions
sudo apt-get install docker.io -y sudo apt-get install docker-compose -y sudo usermod -aG docker $USER sudo usermod -aG docker jenkins sudo reboot
Jenkins : Jenkins is an open-source automation server that is widely used for continuous integration and continuous delivery (CI/CD) of software projects. It helps automate various stages of the software development lifecycle, such as building, testing, and deploying applications.
Continuous Integration: Jenkins allows developers to continuously integrate their code changes into a shared repository, enabling early detection of integration issues and promoting a collaborative development environment.
Continuous Delivery: Jenkins facilitates the continuous delivery process by automating the deployment of software applications to various environments, such as development, staging, and production.
To create your first Jenkins pipeline, follow these steps:
Step 1: Set up Jenkins server
Install Jenkins on your system also we covered in last blog setting up jenkin server
Step 2: Access Jenkins Dashboard.
Once Jenkins is installed and running, access it through your web browser by navigating to http://localhost:8080
(or the URL where Jenkins is hosted).
Step 3: Install the required plugins
Jenkins provides various plugins to enhance its functionality. Install the necessary plugins for creating and running pipelines. You can install plugins by going to "Manage Jenkins" > "Manage Plugins" > "Available" and search for the desired plugins.
Step 4: Create a new pipeline project
On the Jenkins dashboard, click on "New Item" to create a new project.
Enter a name for your pipeline project and select "Pipeline" as the project type.
Click "OK" to proceed to the configuration page.
Select Github project provide URL of public repository.
in Pipeline script write below code:
pipeline { agent any stages{ stage('Code'){ steps{ git url : 'https://github.com/Akv1998/node-todo-app.git', branch :'master' } } stage('Build and Test'){ steps{ sh 'docker build . -t project:latest' } } stage('Deploy'){ steps{ sh 'docker run -d --name project -p 8000:8000 project:latest' } } } }
Click on the save button in blue highlighted.
Go to Jenkin Dashboard all pipeline list will be shown.
Now click on node-todo-cicd-dev pipeline.
Now click on Build Now button
Now the jenkin pipeline has run successfully.
Now open 8000 port from a security group.
Now hit the URL : http://35.171.157.80:8000/todo below web page will open.
sudo docker ps -a // to check running container
Conclusion :
During the process of creating your first Jenkins pipeline, you have learned the concepts and steps to create first jenkin pipeline. You started by installing and configuring Jenkins on your server or machine, ensuring that it is accessible and ready to execute your pipeline. we deployed github repository code on a dockerized running container.