Project Description
The project aims to automate the building, testing, and deployment process of a web application using Jenkins and GitHub. The Jenkins pipeline will be triggered automatically by GitHub webhook integration when changes are made to the code repository. The pipeline will include stages such as building, testing, and deploying the application, with notifications and alerts for failed builds or deployments.
Sign in to your AWS account and create a new instance
- Utilize the User Data field to install Docker and Jenkins during instance initialization.
Launch the Instance:
- Connect to the instance to check if docker and Jenkins are running.
systemctl status docker
systemctl statud jenkins
- Open port 8080, the default port for running Jenkins, on the server and port 8000 to access the webpage.
- Navigate to the URL http://<public url>:8080
- To retrieve the "Administrator password," run the following command:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
- Copy that and paste it in the "Administration password" space and click on continue.
- Then click on "Install suggested plugins" to install all the suggested plugins.
- Create First Admin User: Set up the initial admin user by providing all required input. Save and continue.
Now, Jenkins is ready
- Now, create a Jenkins Pipeline: Click on “New Item” to create a new job. Enter an item name and click on "Freestyle project".
- Provide a description, then click on "GitHub project" and go to GitHub to copy the repository url.
You need to install necessary Jenkins plugins for integration with GitHub
- Click on "Manage Jenkins" in the left sidebar, then select "Manage Plugins" from the dropdown menu.
- Go to the "Available" tab. In the search box, type in "GitHub Integration Plugin"
- Navigate to GitHub and select Webhook. Enter the payload URL. Select the content type as application/json and click on "Add webhook".
http://<publicIP>:8080/github-webhook/
Generate SSH Key:
- After generating the SSH key pair , add the public key to your GitHub account settings. Provide the public key of the server you want to connect to and click on "Add SSH key".
Generate a personal access token in GitHub to establish the connection between GitHub and Jenkins.
- To generate a personal access token on GitHub, follow these steps: click your profile icon, then navigate through "Settings" > "Developer settings" > "Personal access tokens", and finally click on the "Generate new token" button to start creating a new token.
After generating the token, make sure to copy it to a secure place.
In Jenkins, navigate to the setting up global credential.
Select the type "Secret text" and paste the token you copied earlier.
In the "Build Triggers" section, select "GitHub hook trigger for GITScm polling" because a webhook has already been set up, enabling Jenkins to trigger builds in response to webhook notifications from GitHub.
Then, in the build steps, select the "Execute shell" option and add the following to build and run the docker container.
docker build . -t django-notes-app
docker run -d -p 8000:8000 django-notes-app
- Now, Click on Build Now and check the console output.
- To ensure that the previous container is stopped before building and running a new one, let's update the Jenkins job configuration with the following steps:
Modify the code of your web application and push the updates to your GitHub repository.
The Jenkins pipeline will be triggered automatically by GitHub webhook integration when changes are made to the code repository.
- Navigate to the URL <public_IP:8000> and check for the web-application.
Thank you for reading.