Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Configure Bitbucket Webhook to Trigger Jenkins Builds on AWS EC2

DZone's Guide to

Configure Bitbucket Webhook to Trigger Jenkins Builds on AWS EC2

In this tutorial, learn how to trigger Jenkins builds on an AWS EC2 machine with each code commit in your BitBucket repository.

· Cloud Zone ·
Free Resource

Discover a centralized approach to monitor your virtual infrastructure, on-premise IT environment, and cloud infrastructure – all on a single platform.

This article represents the steps required to configure BitBucket Webhooks to trigger Jenkins Builds on AWS EC2 based on code committed in the repository. This essentially means that a code commit in the BitBucket code repository would trigger a build on the Jenkins server running on a AWS EC2 machine. This forms the starting point of a continuous delivery pipeline. The Jenkins build, when triggered as a result of code push, could perform tasks such as some of the following:

  • Run the build.
  • Run tests.
  • Publish build artifacts in artifactory.
  • Deploy the build artifacts in different environments including QA, UAT, and production.

Please feel free to comment/suggest if I missed one or more important points.

Following are the steps which need to be taken to configure the push-based trigger of a Jenkins build:

  • Configure Inbound Rule on Jenkins Server on AWS EC2: One needs to add the inbound rule on the Jenkins box on AWS EC2 to follow this IP: 104.192.143.192/28. This is required to allow requests coming from BitBucket to reach the Jenkins server on AWS EC2. This is the BitBucket cloud IP outbound address (for hooks like POST), while the inbound IP address for BitBucket is 104.192.143.1. The IP (104.192.143.1) can be figured out by pinging bitbucket.org. The outbound IP address can be found on this page.
  • Configure Webhook in BitBucket: One needs to add the following URL while creating the WebHook in BitBucket: http://jenkins_server_uri/bitbucket-hook/.
  • Configure SCM in Jenkins Project: He next step is to configure Git as a source code management tool within the Jenkins project by clicking on the Configure link on the project’s dashboard. Following is a sample of input parameters:
    • Repository_URL: https://<bitbucket_user>@bitbucket.org/<bitbucket_user>/<bitbucket_project_name>.git
    • Credentials: Create a credential by providing a BitBucket username and password.
  • Setup Build Triggers in Jenkins Project: Finally, one would need to setup build triggers for the Jenkins project by clicking on the Configure link on project’s dashboard. Check the option “Build when a change is pushed to BitBucket.”

Learn how to auto-discover your containers and monitor their performance, capture Docker host and container metrics to allocate host resources, and provision containers.

Topics:
cloud ,aws ec2 ,jenkins ,bitbucket ,continuous delivery

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}