Day 81-Project 2(Declarative pipeline)

1 min read

Cover Image for Day 81-Project 2(Declarative pipeline)

prerequisite:

  1. 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.

  2. SSH into the EC2 instance just created. Create SSH private and public keys by ssh-keygencommand. cd .ssh to see the keys.

  3. 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.

  4. Create new item -> pipeline->ok.

  5. 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'
                     }
                 }
             }
         }
     }
    

  6. Hit save and run Build.

    Happy learning!!💕