Task-1
Fork this repository
Create a connection to your Jenkins job and your GitHub Repository via GitHub Integration.
- ssh-keygen generates public and private key-pair. These keys are used for integrating Jenkins project with git repository
id_rsa --> private key
id_rsa.pub --> public key
- To add ssh keys to github, Go to settings.
- Go to SSH and GPG keys.
- Select key-type Authentication key. Add public key that was created using ssh-keygen.
cat id_rsa.pub
In Jenkins, verify github integration plug is installed and enabled.
Configuring Jenkins:
- Open Jenkins Dashboard and click on “New Item” on the left menu
2. Enter the name and select “Freestyle project”
3. In the configure page, provide the github url and mention the appropriate repository branch.
Add private key which was created using ssh-keygen command in the credentials section.
4. Under “Build Trigger” select “GitHub hook trigger for GITScm pollling”.
5. Under “Build Steps” , select “Execute Shell” and add an echo statement and click “Save”.
6. Verify that the build is successful.
- Read About GitHub WebHooks and make sure you have CI/CD setup
Webhooks allow you to build or set up integrations, such as GitHub Apps or OAuth Apps, which subscribe to certain events on GitHub.com. When one of those events is triggered, we’ll send a HTTP POST payload to the webhook’s configured URL. Webhooks can be used to update an external issue tracker, trigger CI builds, update a backup mirror, or even deploy to your production server.
Adding Jenkins Webhook in Github
Open github repository
Go to “settings” and then “Webhooks”
Click “Add webhook” button. The payload url will be “<Jenkins url>/github-webhook/”. Click on Add webhook.
Task-2
- In the Execute shell run the application using Docker compose
- You will have to make a Docker Compose file for this Project (Can be a good open source contribution)
- Run the project and give yourself a treat :)
The build is successful. It can be viewed from console output.
We can verify that the docker container is up and running
Browse public IP address with port 8001.
Since we have integrated the github and jenkins, whenever there is a change in code in github (new commits), new jobs are automatically build and deployed in Jenkins.