Skip to content

CircleCI

Ben Weese edited this page Jun 12, 2019 · 3 revisions

I started out with Gitlab as my job was using it at the time. I didn't know much about the world of docker and configured it to run on a local machine. When I started this project I thought I could use it as it is free but the integration with Gitlab and Github is not the same as other CIs.

Gitlab CI

This will work on a computer or VM with everything installed but I needed to learn Docker and other CIs so I scrapped this and moved to Travis CI.

# Using Gitlab's built in Maven template ant then editing I made this.
stages:	
  - build	
  - test	

 variables:	
  # This will suppress any download for dependencies and plugins or upload messages which would clutter the console log.	
  # `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work.	
  MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"	

# As of Maven 3.3.0 instead of this you may define these options in `.mvn/maven.config` so the same config is used when running from the command line.	
# `installAtEnd` and `deployAtEnd` are only effective with recent version of the corresponding plugins.	
  MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"	

# Cache downloaded dependencies and plugins between builds.	
# To keep cache across branches add 'key: "$CI_JOB_REF_NAME"'	
cache:	
  paths:	
    - .m2/repository	

# Validate goes into the main directory and test to see everything compiles.	
validate:	
  stage: build	
  script:	
    - mvn $MAVEN_CLI_OPTS test-compile	
  tags:	
    - maven	

# Run test actually runs the test you have scripted then runs Verify to refresh the reports generated by Serenity.	
# Then stores the Serenity reports as an artifact to be downloadable.	
run test:	
  stage: test	
  script:	
    - mvn $MAVEN_CLI_OPTS clean test -Dtest=TestRunner.runner.java	
    - mvn $MAVEN_CLI_OPTS verify	
    - cp -r target/site/serenity reports	
  artifacts:	
    when: always	
    paths:	
      - reports	
    expire_in: 1 week	
  tags:	
    - maven 

Travis CI

I tried out Travis CI and I liked it. However it never ran the correct maven command. I asked it to run mvn clean test -Dtest=TestRunner.runner.java and it would always run:

mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
mvn test -B

Which meant that the test would always be skipped and my command never ran correctly. Also I was unable to run on private repos.

  language: java	
jdk:	
  - openjdk12	
addons: # get google-chrome-stable	
  chrome: stable	
cache:	
  directories:	
    - ${HOME}/.m2	
install: # Install ChromeDriver (64bits; replace 64 with 32 for 32bits).	
  - wget -N http://chromedriver.storage.googleapis.com/2.30/chromedriver_linux64.zip -P ~/	
  - unzip ~/chromedriver_linux64.zip -d ~/	
  - rm ~/chromedriver_linux64.zip	
  - sudo mv -f ~/chromedriver /usr/local/share/	
  - sudo chmod +x /usr/local/share/chromedriver	
  - sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver	

   script:	
  - whereis google-chrome-stable	
  - whereis chromedriver	
  - mvn clean test -Dtest=TestRunner.runner.java

CircleCI

So after using Travis CI and watching my Minecraft youtube videos. Youtube advertised CircleCI at me at all hours of the day. So I though I would try it and used the following links to setup my .circleci/config.yml.

You can also setup CircleCI for private repos, it has unlimited repos and users. It is fully integrated in with Docker, you get 1 container, and one job. This is only for Linux but for Github projects for a single person this seems to be the best setup I found.

# Java Maven CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-java/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/openjdk:8-jdk
      - image: circleci/node:jessie-browsers
      
      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/postgres:9.4

    working_directory: ~/repo

    environment:
      # Customize the JVM maximum heap limit
      MAVEN_OPTS: -Xmx3200m

    steps:
      - checkout
      - run: mkdir test-reports
      - run:
          name: Download Selenium
          command: curl -O http://selenium-release.storage.googleapis.com/3.5/selenium-server-standalone-3.5.3.jar
      - run:
          name: Start Selenium
          command: java -jar selenium-server-standalone-3.5.3.jar -log test-reports/selenium.log
          background: true

      # Download and cache dependencies
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "pom.xml" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-

      - run: mvn dependency:go-offline

      - save_cache:
          paths:
            - ~/.m2
          key: v1-dependencies-{{ checksum "pom.xml" }}

      # run tests!
      - run: mvn clean test -Dtest=TestRunner.runner.java
Clone this wiki locally