# Static Webpage deployment using Git-Jenkins-Docker-Nginx

1. Install Jenkins using below commands for Ubuntu 22.04
    
    ```bash
    apt-get update
    
    apt install openjdk-11-jre
    
    curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
      /usr/share/keyrings/jenkins-keyring.asc > /dev/null
      
    echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
      https://pkg.jenkins.io/debian binary/ | sudo tee \
      /etc/apt/sources.list.d/jenkins.list > /dev/null
      
    sudo apt-get update
    
    sudo apt-get install jenkins
    ```
    
2. Port 8O8O should be open to access Jenkins, if its busy already use the below command and change the port.
    

```bash
systemctl edit jenkins

[Service]
Environment="JENKINS_PORT=8080"

Change 8080 to whatever port is available.
```

1. open http://&lt;IP&gt;:8080 and enter Admin password which is available in the below path.
    
    ```bash
    cat /var/lib/jenkins/secrets/initialAdminPassword
    ```
    
2. Install the required plugins and pass the initial username, passwords and continue.
    
    Install Docker using official documentation- [https://docs.docker.com/engine/install/ubuntu/](https://docs.docker.com/engine/install/ubuntu/)
    
3. Run the below commands to give access to Jenkins users to run docker commands in the server.
    
    ```bash
    chmod 666 /var/run/docker.sock
    ```
    
4. Now open Jenkins UI and click on New Item and name it a simple app and select Pipeline.
    

![](https://blogs.q21.in/content/images/2023/04/image-5.png align="left")

1. 1. Select the GitHub project and enter the link to the repository below.
        

```bash
https://github.com/prashanthgowdagr/simple-index.html-app.git
```

![](https://blogs.q21.in/content/images/2023/04/image-2.png align="left")

1. Scroll down and select the GitHub hook trigger. This will help us to build the Jenkins job whenever the commit is made to the 'MAIN' branch of the Git repo.
    
    ![](https://blogs.q21.in/content/images/2023/04/image-7.png align="left")
    
2. To set this up go to GitHub and under repo go to settings&gt; Webhooks&gt; and paste the Jenkins server IP address with port number and end with GitHub-webhook/ (don't forget the / in the end). Select Just the push event and save the changes.
    
    ![](https://blogs.q21.in/content/images/2023/04/image-6.png align="left")
    
3. Under Pipeline select Pipeline script from SCM and select GIT as SCM.
    
4. Enter Git repo URL and branch as main. The script path should be specified as Jenkinsfile.
    
5. Before running the job go to Manage\_Jenkins&gt; Credentials&gt; system&gt; golbal&gt; name it "dockercreds" (Use same or it will throw an error/change the variable in jenkinsfile) and enter your DockerHub creds and password. If there is no DockerHub account, plz create one it's FREE!!!
    
6. Run the job now and this will pull the code from Git and copy the index.html into the docker container and runs it. You can access  the webpage now using http://&lt;IP&gt;:80
    
7. This will also push the updated container to DockerHub with the tag 'latest' and also with the 'Jenkins Build Number'.
