Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds SonarQube execution script #9

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,38 @@ script:

Note that any of the above environment variables can be set in Travis, and do not need to be included in your .travis.yml. `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` should always be set to your S3 bucket credentials as environment variables in Travis, not this file.

## SonarQube

Included in the repository is a `sonarqube.sh` execution script. This script will execute Gradle builds using SonarQube
analysis either as a PR or as a general version build. Due to the added overhead Sonarqube adds to the build, its recommended to
configure Travis to run the analysis after the general build and deployment.

**Note:** Usage of this script requires an administrator setting the `SONAR_TOKEN` environment variable in your Travis
configuration. This token can be obtained via your associated SonarCloud console. If the token is not present, the build
will exit with status 1.

Here is an example `travis.yml` configuration using Sonarqube:

```yaml
language: java

branches:
only:
- develop
- /^v\d.*$/

jdk:
- openjdk8

install: true

env:
global:
- DEPLOY_SOURCE_DIR=site/build/libs

before_script:
- git clone https://github.com/perfectsense/travis-s3-deploy.git

script:
- ./travis-s3-deploy/build-gradle.sh && ./travis-s3-deploy/deploy.sh && ./travis-s3-deploy/sonarqube.sh
```
24 changes: 24 additions & 0 deletions sonarqube.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -e

# Set a default JAVA_TOOL_OPTIONS if it hasn't already been specified in .travis.yml
export JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS:--Xmx4096m}"

if [[ -z "${SONAR_TOKEN:-}" ]]; then
echo "SonarCloud token not present in the environment. Aborting."
exit 1
fi

echo "======================================"
echo "Running SonarQube Analysis"
echo "======================================"

if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then
./gradlew sonarqube -i -Dsonar.pullrequest.key="$TRAVIS_PULL_REQUEST"
else
version=$(git describe --tags --match "v[0-9]*" --abbrev=0 HEAD || echo "0")
version=${version/v/}
echo "Creating a new analysis for version ${version}"
./gradlew sonarqube -i -Dsonar.projectVersion="${version}"
fi