diff --git a/.circleci/config.yml b/.circleci/config.yml index 750004da..bafe6b67 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,9 +1,20 @@ version: 2 jobs: - build: + build-project: docker: - - image: checkstyle/sonarqube-maven-git:7.7-community-8c1737e + - image: cimg/openjdk:11.0.16 + steps: + - checkout + - run: mvn package -Pno-validations + - persist_to_workspace: + root: /home/circleci + paths: + - project + + execute-sonar: + docker: + - image: sonarqube:9.0-community working_directory: ~/repo environment: @@ -11,44 +22,40 @@ jobs: MAVEN_OPTS: -Xmx3200m steps: - - checkout + - attach_workspace: + at: /root + - run: + name: Install packages + command: apk add maven + - run: + name: Copy jar + command: | + cp /root/project/target/checkstyle-sonar-plugin*.jar \ + /opt/sonarqube/extensions/plugins/ + - run: + name: Start SonarQube web service and execute maven SonarQube build + command: | + # start SonarQube web server + cd /opt/sonarqube/ + ./bin/run.sh & + until grep "SonarQube is up" logs/sonar.log; \ + do sleep 10 && echo "Waiting for web server to come up..."; \ + done - # Download and cache dependencies - - restore_cache: - keys: - - v1-dependencies-sonarqube-{{ checksum "pom.xml" }} - # fallback to using the latest cache if no exact match is found - - v1-dependencies-sonarqube + # Note that we cannot separate "start SonarQube web server" above from + # this step, as we would kill web server when step is complete. + cd /root/project + mvn sonar:sonar -Dsonar.login=admin -Dsonar.password=admin + - run: + name: Check logs for error + command: grep "ERROR" /opt/sonarqube/logs/* || test $? = 1 - - run: mvn package -Pno-validations - - - save_cache: - paths: - - ~/.m2 - key: v1-dependencies-sonarqube-{{ checksum "pom.xml" }} +workflows: + version: 2 - # run tests - - run: |- - pwd - POM_VERSION=$(grep "" pom.xml | head -n 1 | sed -E "s/.*//" | sed "s/<.*//") - echo "POM_VERSION="$POM_VERSION - echo "creation of jar is skipped as it was created on previous step" - #mvn package -Pno-validations - echo "coping jar to sonarqube ..." - cp target/checkstyle-sonar-plugin-$POM_VERSION.jar /opt/sonarqube/extensions/plugins/ - cd /opt/sonarqube/ - echo "remove existing logs ..." - rm -f logs/*.* - echo "run sonarqube web service" - ./bin/run.sh & - echo "sleeping 60 to let sonar start up ..." - sleep 60 - echo "check that sonar service is up ..." - grep "SonarQube is up" logs/sonar.log - echo "switching back to repository code" - cd - - pwd - echo "execution of mvn sonar:sonar ..." - mvn sonar:sonar - echo "grep for ERROR in logs ..." - grep "ERROR" /opt/sonarqube/logs/* || test $? = 1 + build-sonar: + jobs: + - build-project + - execute-sonar: + requires: + - build-project \ No newline at end of file