CircleCI
CircleCI is a cloud-based CI/CD tool, but an on-premise solution is also available. CircleCI automatically runs your build in a clean container or virtual machine, allowing you to test every commit. It supports any language that builds on Linux, Windows, or macOS, including C++, Javascript, .NET, PHP, Python, and Ruby.
Create a CircleCI account and integrate it with a Maven project. A sample project is available here: https://github.com/PerfectoMobileSA/MavenCircleCISample
To integrate CircleCI with a Maven project:
-
Follow the CircleCI instructions at the following link to sign up and try CircleCI for free: https://circleci.com/docs/2.0/first-steps/
You sign up with your GitHub or Bitbucket account.
- Perform the instructions provided in the readme.md file.
- To help CircleCI webhooks to listen for git updates, create the following in the root of your repository:
- A folder called
.circleci
- A
.yml
file calledconfig.yml
The file path to this file should be:.circleid/config.yml
- A folder called
-
In the
config.yml
file, add the following code. The content is self-explanatory.CopyConfig file content
version: 2.1 # use CircleCI 2.1
jobs: # a collection of steps
build: # runs not using Workflows must have a `build` job as entry point
working_directory: ~/MavenCircleCISample # directory where steps will run
docker: # run the steps with Docker
- image: circleci/openjdk:8-jdk-stretch # ...with this image as the primary container; this is where all `steps` will run
steps: # a collection of executable commands
- checkout # check out source code to working directory
- restore_cache: # restore the saved cache after the first run or if `pom.xml` has changed
# Read about caching dependencies: https://circleci.com/docs/2.0/caching/
key: MavenCircleCISample-{{ checksum "pom.xml" }}
- run: mvn dependency:go-offline # gets the project dependencies
- save_cache: # saves the project dependencies
paths:
- ~/.m2
key: MavenCircleCISample-{{ checksum "pom.xml" }}
- run: mvn clean install -B -DcloudName=${cloudName} -DsecurityToken=${securityToken} -Dreportium-job-name=${CIRCLE_PROJECT_REPONAME} -Dreportium-job-number=${CIRCLE_BUILD_NUM} -Dreportium-job-branch=${CIRCLE_BRANCH} -Dreportium-tags="test" - run: echo "Perfecto Suite Report- https://${cloudName}.reporting.perfectomobile.com/library?jobName[0]=${CIRCLE_PROJECT_REPONAME}&jobNumber[0]=${CIRCLE_BUILD_NUM}" - store_test_results: # uploads the test metadata from the `target/surefire-reports` directory so that it can show up in the CircleCI dashboard.
# Upload test results for display in Test Summary: https://circleci.com/docs/2.0/collect-test-data/
path: target/surefire-reports
workflows: # The following yaml will schedule this maven build operation to run every day at 12:00am UTC
version: 2
commit:
jobs:
- build
nightly:
triggers:
- schedule:
cron: "0 0 * * *" filters:
branches:
only:
- master
jobs:
- buildConsider the following:
- Replace
MavenCircleCISample
with your project folder name. - The
run
command contains the Maven goals. You can tweak them as needed for your project. -
For enhanced security and as a best practice, we add the
cloudName
(for exampledemo
) and the Perfecto security Token as environment variables to our project. Follow the steps here to set up environment variables for your project. For information on security tokens, see Generate security tokens. - CircleCI automatically builds for every commit and performs a nightly execution at 12:00am UTC due to a nightly trigger workflow.
-
You can add CircleCI status badges to your
readme.md
file. For example, the following code will showcase the current build status of CircleCI in GitHub:![CircleCI status](https://circleci.com/gh/PerfectoMobileSA/MavenCircleCISample.svg?style=shield "CircleCI status"
For instructions, see here.
- Replace