Skip to content

Commit

Permalink
infra: fix build and plugin execution
Browse files Browse the repository at this point in the history
  • Loading branch information
nrmancuso committed Oct 22, 2022
1 parent f7f93d4 commit 6bed351
Showing 1 changed file with 47 additions and 40 deletions.
87 changes: 47 additions & 40 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,61 @@
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:
# Customize the JVM maximum heap limit
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 "<version>" pom.xml | head -n 1 | sed -E "s/.*<version>//" | 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

0 comments on commit 6bed351

Please sign in to comment.