Pull Request Validation Between Jenkins and Bitbucket

Icaro Bichir
Jul 26, 2017 · 3 min read

In the end of this tutorial, your Jenkins will execute every Bitbucket open pull request and post a comment with the commit number, link to console output, link to coverage report.


Go to my page and fork the master version of shell script.

  • Your comments on bitbucket will be just like this:

Configuration

Install Gitbucket plugin on your Jenkins and Create a new job on your Jenkins and select the option:

Build multi-configuration project

  • Settings Screen

Inside GitBucket config, select This build is parameterized and create one parametrized value for each variable above:

* OWNER = bitbucket owner
* BUCKET_API_V1_URL = bitbucket.org/api/1.0/repositories
* BUCKET_API_V2_URL = api.bitbucket.org/2.0/repositories
* REPO = $repository
* USERNAME_BITBUCKET = username
* PASSWORD_BITBUCKET = p4ssw0rd
* USERNAME_JENKINS = username
* PASSWORD_JENKINS = p4ssw0rd
* JENKINS_URL = your_jenkins_url.com
* LANGUAGE = program language (python or ruby)

”Source Code Management”

Select ”Git” and insert your bitbucket link with this pull request script.

”Build Triggers”

Select ”Poll SCM” and insert your crontab to Jenkins validade with bitbucket if there is a open PR. In my project, the Jenkins validate every 5 minutes.

H/5 * * * * 

”Configuration Matrix”

Create a ”User Defined Axis” with the ”name: repository” and on the values, insert your Bitbucket repository name.

”Build”

Include this script on the ”Execute Shell”

#!/bin/bash./pr-response.sh
  • Configure Code analisys

”Post Build Actions”

> On Python

Activate the Cobertura Plugin ”Publish cobertura coverage Report” and insert the location of the coverage report, on .xml format.

**/coverage.xml

> On Ruby

The ruby coverage will be generated on HTML format.



VERY Important Note

ci.sh is the file when I execute my environment configuration to run the tests.

## Your PYTHON .html coverage report MUST be on this path:
http://${JENKINS_URL}/job/${JOB_NAME}/repository=${REPOSITORY_NAME}/ws/${REPOSITORY_NAME}/htmlcov/index.html
## Your RUBY .html coverage report MUST be on this path:
http://${JENKINS_URL}/job/${JOB_NAME}/repository=${REPOSITORY_NAME}/ws/${REPOSITORY_NAME}/coverage/index.html

Thanks for your attention and be welcome to send me a message if you have any question or improvement to this post.

See Ya

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade