Nick's Blog

Use Jenkins in GCP to connect to GitHub and receive webhooks

I created a Jenkins compute instance based on Google Click to Deploy. It’s a deployment that include vm instance and the jenkins application. You will get the username and password straight way after the deployment completed.

After the deployment finished. I’m going to connect Jenkins into my GitHub account, so that I can do polling and receive web-hooks from github repos.

Create a connector token in Github:
GitHub > avatar > settings > developer settings > personal access tokens > generate a new token > Give it a name “nick-jenkins-connector” > give repo:*/admin:repo_hook*/notifications:* > click “Generate” > copy your token into a safe place for future use

Add connector token into Jenkins:
Go to Jenkins > Manage Jenkins > Configure System > GitHub > add GitHub Server > Add Credential – Jenkins > select Secret text option from Kind > paste token into secret and give a ID (prefer to have the same name as GitHub) > Click Add > Choose the previous credential > click Test Connection > You will receive a success message if it set up correctly

Create a webhook token in GitHub:
repeat the same steps above to create another token called “jenkins-webhook” and copy the token

Add webhook token into Jenkins pipeline:
Go to Jenkins > Create a multibranch pipeline and give it a name “jenkins-webhook” > Branch Source > select “GitHub” > Add Jenkins Credential > use your GitHub username and token as your password > give it a id “jenkins-webhook-id” > fill the owner the same as your repo’s username > select your repository name and you are good to go.