0% found this document useful (0 votes)
16 views4 pages

Experiment No - 5

Uploaded by

Manu Manu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Experiment No - 5

Uploaded by

Manu Manu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

EXPERIMENT NO: 5.

Demonstrate continuous integration and development using


Jenkins.
Setting Up Nginx on Windows with Jenkins and GitHub Integration
Step 1: Installing Nginx on Windows
Download Nginx:

Go to the official Nginx website and download the stable version of Nginx for Windows.
Extract the Nginx Files:

Extract the downloaded .zip file to a directory of your choice, for example, C:\nginx.
Start Nginx:
double click on Nginx --- C:\nginx-1.26.2
Nginx should now be running, and you can verify it by opening your browser and going to
http://localhost. You should see the Nginx welcome page.

Step 2: Configure Nginx to Serve a Custom Web Page


Replace the Default Page:
The default page is located in the C:\nginx\html\index.html file.
Replace this with your own index.html [remove the index.html file and copy
Registration_form.html and styles.css and rename registration_form.html to index.html] file
by copying it into the C:\nginx\html\ directory:

Test Your Custom Page:


Refresh your browser at http://localhost to see your custom page served by Nginx.
Step 3: Set Up GitHub Repository
Create a GitHub Repository:
Create a new repository on GitHub.
Clone the repository to your local machine:

[in git bash]


#git clone https://github.com/yourusername/your-repo.git
Add your index.html file to the repository:

#cd jenkinsproject
#copy index.html and styles.css to Nginx/html [dirctory which we created early.]
#copy C:\path\to\your\index.html .
#git add index.html
#git commit -m "Initial commit"
#git push origin main

Step 4: Configuring Jenkins for Continuous Deployment


Create a Jenkins Job:
In Jenkins, create a new Freestyle project.
1) Under Source Code Management, select Git and enter the URL of your GitHub repository
[new repository url].
2) Provide credentials - add-username and password of github.
3) Configure Build Triggers:
Enable GitHub hook trigger for GITScm polling under Build Triggers.
4) Set Up Build Steps:
In the Build section, add a Windows batch command step with the following commands:

#REM Pull the latest changes from GitHub


#git pull origin main

#REM Copy the updated index.html to the Nginx directory


#copy index.html C:\nginx-1.26.2\html\index.html
#copy styles.css C:\nginx-1.26.2\html\styles.css

Step 5: Manual build


1) Modify your index.html file a bit and push it to remote repository.
2) In Jenkins Project page click on "Build Now " to triggger the build manually.
3) Refresh the website hosted on localhost if the changes are dployed or not.
Step 6: Installing and Setting up Ngrok to expose our localhost:8080 to outside world(github
wenhook prerequisite)
1) Download and Install ngrok
Download ngrok:

Visit the ngrok website and sign up for a free account.


After signing up, download the ngrok executable for Windows.
Install ngrok:

Extract the downloaded .zip file to a directory of your choice.

2) Connect Your ngrok Account


Open executable file and paste the auth token command given in your ngrok website:

Run the following command to authenticate ngrok with your account (you'll get an authtoken
from the ngrok dashboard):
# ngrok config add-authtoken
2lTQVCGs8mBCi6skY7H3FtBjtJa_47gtxMnH5L12HTVttjPJ2
3) Expose Jenkins on Port 8080:

Assuming Jenkins is running on port 8080, run the following command in Command Prompt:

#ngrok http 8080


This will create a public URL that tunnels traffic to http://localhost:8080.
Note the Public URL:

Once ngrok is running, it will display an HTTP and HTTPS URL. This URL is now
accessible from the internet and will forward requests to your local Jenkins instance.
Example output might look like:

Forwarding https://abcd1234.ngrok.io -> http://localhost:8080


4) Verifying if ngrok setup is working or not:
Open the obtained URL in a new tab in chrome.
Select `visit site` if a certificate related issue is shown while accessing th website.
ER: Jenkins page should be accessible.

Step 7: Setting Up GitHub Webhook


Add a Webhook to Your GitHub Repository:
Go to Settings -> Webhooks in your GitHub repository.
Add a new webhook with the following details:
1) Payload URL: http://<your_localhost>:8080/github-webhook/
2) Content type: application/json
3) SSL verification: Disable(not recommended)
4) Trigger: Just the push event

Step 8: Testing the Setup


Make a Change to index.html:
Modify index.html in your local repository.
Commit and push the changes to GitHub:

#git add index.html


#git commit -m "Updated index.html"
#git push origin main

Check Jenkins:
Jenkins should automatically start a build when it detects the push.
After the build completes, check http://localhost to see the updated page served by Nginx.

You might also like