Day 81-Project 2(Declarative pipeline)
1 min read
![Cover Image for Day 81-Project 2(Declarative pipeline)](https://cdn.hashnode.com/res/hashnode/image/upload/v1694753873541/6c04948a-22f8-4f6e-8811-ac613611288f.png?w=1600&h=840&fit=crop&crop=entropy&auto=compress,format&format=webp)
prerequisite:
AWS EC2 instance with docker and Jenkins installed in it.
For creating an EC2 instance:
· AMI: ubuntu.
· Instance type: t2.micro (free tier).
· Key pair login: Create > docker.pem.
· Allow HTTP.
· Allow HTTPS.
. Docker installation:
sudo apt install Docker.io -y
. Jenkins installation: Link
. Allow TCP on ports 8000 and 8080 by editing the inbound security group.
SSH into the EC2 instance just created. Create SSH private and public keys by
ssh-keygen
command.cd .ssh
to see the keys.Setup Jenkins, you can check my blog on it: (You can check the Jenkin server at
http://<public_ip_addr_ec2>:8080/
)https://sri766.hashnode.dev/jenkins
After configuring Jenkins, just log in with a username and password.
Create new item -> pipeline->ok.
pipeline syntax
pipeline { agent any stages { stage('Checkout') { // Give your stages a name steps { script { git branch: 'main', url: 'https://github.com/sri766/react_ci-cd_app.git' } } } stage('Testing') { steps { echo 'Testing' } } stage('Docker Build') { steps { script { sh 'sudo docker build --no-cache -t react_django_demo_app .' } } } stage('Docker Run') { steps { script { sh 'sudo docker run -p 8001:8001 -d react_django_demo_app' } } } } }
Hit save and run Build.
Happy learning!!💕