Day 24 Task: Complete Jenkins CI/CD Project

Day 24 Task: Complete Jenkins CI/CD Project

Task-01

Fork this repository in your GitHub: github.com/LondheShubham153/node-todo-cicd

  • Now, click on 'Code', copy the HTTPS link, and clone it in your system using the following command:
 git clone https://github.com/LondheShubham153/node-todo-cicd.git

Create a connection to your Jenkins job and your GitHub Repository via GitHub Integration.

  • login to your Jenkins server

  • Step 1: Click on a new item, and then you will have a page on which you have to give your name to your job and choose ‘freestyle project’ or any other option according to your need and then click ‘ok’.

  • Step 2: After this, you will reach a page where you have different options(like build, build triggers, and source code management) that help you manage your job.

  • Step 3: And Write the description "This is node js todo app" and click on the GitHub project and past the GitHub repository URL.

  • Step 4: Come to Source Code Management and click on Git and past the repository URL

  • Step 5: Create a connection to your Jenkins job and your GitHub Repository via GitHub Integration for that go to your local machine and write the command
cd .ssh

ssh-keygen

  • Step 6: If I need to connect GitHub to my server, I'd recommend using a public key. Open your GitHub account, navigate to 'Settings', and there you'll find 'SSH and GPG keys'. Click on 'New SSH key', title it as 'Jenkins-project', paste your public key into the provided field, and finally, click on 'Add SSH key'.

  • To know our Jenkins public key

cat jenkins.pub

  • Step 7: Go to your Jenkins server, navigate to 'Source Code Management', click on '+Add', then select 'Jenkins'. Choose 'SSH Username with private key' as the kind, set the ID as 'github-jenkins', and provide a description like 'Integration for Jenkins and GitHub'. For the username, enter 'ubuntu', and click 'Enter directly' under 'Private Key'. Paste your private key, then click 'Add'. Choose your 'ubuntu (Integration for Jenkins and GitHub)' in credentials. Ensure that the GitHub branch and Jenkins branch are identical.

  • To know our private key

 cat jenkins

  • Step 8: After that go to build steps select execute shell and write these commands
  echo "Code Cloned"
  docker build . -t node-app

  echo "Code built..!!"
  docker-compose down
  docker-compose up -d
  echo "Container is up"

Then click apply and save. So, your job is created.

  • Step 9: Now, we will run it for which click the ‘build now’ option and a building history will be created then click on it.

  • Step 10: Now, Click on console output, and you can see your output. Also, by console output, you can see whether your job has failed or been successful.
  • Step 11: Now, open AWS, navigate to your instance, select 'Security', click on the security group, and choose 'Edit inbound rules'. Click on 'Add rule', set the port range as 8000, select 'anywhere-ipv4' in the source, and save the rules.

Select the IP address of your AWS instance, copy it, and paste it into a new tab followed by port number 8000.

Read About GitHub WebHooks and make sure you have a CICD setup. Now let's try this

  • open your node-todo-app Configuration and select the GitHub hook trigger for GITScm polling and click on apply and save

  • go to your node-todo-repository

  • click on settings there you will see webhook click on it

  • click on add webhook and in the payload URL write like this ipv4:8080/github-webhook

  • click on Send Me Everything

  • click on add Webhook

  • refresh the page and you will see this

  • now if you change anything in GitHub it will be built-in Jenkins server