Jenkins

What we ended up doing was installing Jenkins in an Amazon EC2 instance with Nginx. You can find an installation guide here.

We needed several plugins to integrate Jenkins with GitHub and have a Travis CI like a flow:

GitHub Plugin

GitHub Authentication Plugin

GitHub Pull Request Builder: For more information about how to setup this plugin read this and this.

For more information about how to setup this plugin read this and this. Post Build Script Plugin

Parameterized Trigger

Matrix Project Plugin: This Plugin lets you manage project permissions for GitHub users.

You can install all of them by going to Manage Jenkins > Manage Plugins

To have a similar flow to Travis CI we added two different jobs:

JobName : A job that builds any Pull Request created.

: A job that builds any Pull Request created. JobName-Base: A job triggered by a Pull Request job. It builds the base branch of the project every time the associated Pull Request job has a successful status.

Let’s setup the jobs now!

JobName

Name: YouProjectName

GitHub project: https://github.com/Wolox/your-repositoy-name

Source Code Management: Git

You need to set Refspec with:

+refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin/pr/*

You can add an SSH credential for your repository. This can be done in Credentials.

Check GitHub Pull Request Builder and add the following information:

Commit Status Context: The name you would like GitHub to show in the Pull Requests when running your Jenkins job. List of organizations. Their members will be whitelisted: You can add your organization’s GitHub name here. Check Allow members of whitelisted organizations as admins. Check Build every pull request automatically without asking (Dangerous!).

Build Execute Shell:

So, this is the script we are going to execute every time the job is triggered. We have several steps:

Remove unnecessary files to free some space. Build a docker compose container. This will run the Dockerfile that we will setup later. Prepare the test database. Run Tests, lints or whatever script you like. We chose Rspec and Rubocop Lint.

Unbuffer will output your script logs with pretty colors. It’s necessary to add set -e at the beginning of the script for Jenkins to fail if any previous step failed. If you avoid adding set -e, then it will only fail if the last step failed (in this case the Rubocop lint).

Add Set status “pending” on GitHub commit build step.

build step. Add a Post-build Actions Execute Shell build step to remove some Docker dangling files:

This will remove idle containers and images to free some space. Actually Docker has some issues with space so you can run this script with a cron.

Add a Trigger Parameterized build on the other projects build step:

This will let us trigger the JobName-Base job when our Pull Request build is successful. This is the only setup that worked for us. There are some other Jenkins Plugins that should resolve this without needing to make a new Job. But they didn't work as we expected.

Now it is time to set the Base Job!

JobName-Base

You can create this Job by cloning the one above. The setup is quite similar.

Name: YouProjectName-Base or whatever name you like

GitHub project: https://github.com/Wolox/your-repositoy-name

Check This build is parameterized and add:

Source Code Management: Git. Here we added the same configuration as used on the other Job.

Uncheck GitHub Pull Request Builder. We are not triggering this Job with a Pull Request.

We are not triggering this Job with a Pull Request. Build Execute Shell: Same as the other job.

Post Build Action: Same as the other job.

Remove Trigger Parameterized build on other projects’ build step.

Every time someone makes a Pull Request, our JobName will be triggered and if the build is successful, then the JobName-Base will be triggered. We chose origin/development as our base branch, but you can change this in the job parameters.