Module 6: Jenkins Assignment - 1

Tasks To Be Performed:

  1. Trigger a pipeline using Git when push on develop branch
  2. Pipeline should pull Git content to a folder

Prerequisite


Installing Jenkins On AWS

I create a repository named JenkinsAssignment on GitHub and then create a develop branch within it.

Note

My terminal is already set up to be able to clone using SSH.

I’ll create Freestyle job called Job1
Dashboard > New Item



We’ll be working with branch develop
We want the job to be triggered by a GitHub webhook.
We want this job to execute in Slave1
Save

In GitHub, we set up the webhook. We navigate to ‘Webhooks’ in the repository settings.
Click on “Add webhook”

Enter the public IP address of the EC2 instance hosting Jenkins, followed by the Jenkins port, which is 8080.
Click button “Add webhook”

Warning

I need to be careful when restarting my EC2 instance (Jenkins Master), as this will change the public IP address.

Success

GitHub sends a ping to test it out.

We navigate back to our Jenkins dashboard, select ‘Job1,’ and execute it by clicking ‘Build Now.’

If I click on the build and check its ‘Console Output,’ I can see that it was started by me and that it was successful.

To test the webhook, I’ll make a push to the develop branch. I’ll clone the repository, switch to the develop branch, create a file somefile, and then push it.

Success

We get another build this time triggered by the POST request that GitHub sends instead of ”Build Now” button.

Success

Now, if we check inside the ‘Slave1’ node, we can see ‘Job1’s’ workspace, which contains the contents from the repository.