CircleCI is a popular service for continuous integration, allowing you to run test suites, perform builds, and even deploy to servers in an automated fashion.
RBCommons can integrate with CircleCI to do test builds of code changes and report the results back as a status update on the review request.
You can have multiple different CircleCI configurations (up to your plan limit), in the case where you may need to have review requests on different repositories use different CircleCI API keys.
CircleCI 2.0 is required. If you’re still using CircleCI 1.0, you’ll need to update first.
- In your Team Administration page, navigate to Integrations and then click Add Integration -> CircleCI.
- Provide a descriptive name for this configuration in the Name field.
- Configure the Conditions in which a build will be triggered.
If you want to trigger builds for all code changes, this can be set to Always match. However, you can also create complex rules for which review requests will match.
Because CircleCI only works with GitHub and Bitbucket repositories, only changes on repositories configured with those hosting services will trigger builds.
- Provide the API Token from CircleUI.
These can be created by going to CircleCI and selecting User Settings from the menu at the top right. From there, select Personal API Tokens.
- Optionally, set the Build Branch field.
By default, the CircleCI user interface will show all builds as occurring on
master. This field allows you to override the branch name to be something else, as to separate review request builds from regular builds.
Note: We recommend creating and pushing a dummy branch named “review-requests” to your repository, and then filling in that name here. The actual contents of that branch are unimportant, and it never needs to be updated, since the source will be completely replaced during the build process.
If at any point you want to stop triggering builds but do not want to delete the configuration, you can uncheck Enable this integration.
CircleCI config.yml Configuration
CircleCI has no built-in support for doing test builds of patches, so RBCommons will trigger a build using a special job name and pass in information in the environment which will allow you to set up the build using
There are several environment variables which will be passed in to your build:
REVIEWBOARD_SERVER- The URL to your team on RBCommons (e.g.,
REVIEWBOARD_REVIEW_REQUEST- The ID of the review request.
REVIEWBOARD_DIFF_REVISION- The revision of the diff to build.
REVIEWBOARD_API_TOKEN- An API token to use when communicating with RBCommons.
REVIEWBOARD_STATUS_UPDATE_ID- An internal identifier used when reporting status back to RBCommons.
In order for builds with RBCommons to work, the
.circleci/config.yml file must define a job named
reviewboard, and a webhook notification. The job should look substantially similar to your normal
build job, but with the addition of a step at the beginning to apply the patch from RBCommons. This should also not include anything that you don’t want to run on uncommitted changes, such as deployments.
This is an example
.circleci/config.yml file which sets up a Python 2.7 environment, installs dependencies, and runs a unit test script. As you can see, the steps for the
reviewboard job are virtually identical to the
buildjob, except there’s an extra one at the start which applies the patch using rbt patch.
jobs: build: docker: - image: circleci/python:2.7 steps: - checkout - run: name: Install dependencies command: sudo python setup.py develop - run: name: Run tests command: python ./tests/runtests.py reviewboard: docker: - image: circleci/python:2.7 steps: - checkout - run: name: Apply patch command: | sudo pip install rbtools rbt patch --api-token "$REVIEWBOARD_API_TOKEN" --server "$REVIEWBOARD_SERVER" --diff-revision "$REVIEWBOARD_DIFF_REVISION" "$REVIEWBOARD_REVIEW_REQUEST" - run: name: Install dependencies command: sudo python setup.py develop - run: name: Run tests command: python ./tests/runtests.py notify: webhooks: - url: https://reviewboard.example.com/rbintegrations/circle-ci/webhook/