Ícaro Bichir bio photo

Ícaro Bichir

Geek that dreams to be a hacker, became a intern security, a DevOps Analyst and now, SysAdmin with DevOps Engineering thinking. ;)

Email LinkedIn Github Last.fm

General Vision

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


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

Your comments on bitbucker will be just like this:

bitbucket_link


Configuration

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 pullrequest script.

bitbucket_link

“Build Triggers”

Select “Poll SCM” and insert your crontab to Jenkins validade with bitbucet 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, inseert your Bitbucket repository name.

bitbucket_link

“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

bitbucket_link

On Ruby

The ruby coverage will be generated on HTML format.


This script will bee function only if you are using python or ruby language and configure coverage report on your tests.


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