Skip to content

Commit

Permalink
Add support for SonarQube servers without versions
Browse files Browse the repository at this point in the history
Older versions of SonarQube don't put a serverVersion property
into sonar-report.txt. It is possible, to fetch the server version
by using the REST API, though.

Fixes #11
  • Loading branch information
headcr4sh committed Jan 23, 2018
1 parent 364d01d commit d7b389e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.0.31] - 2018-01-23

### Fixed

- Support old SonarQube servers that don't report the server version in sonar-report.txt [(#11)(https://github.com/cathive/concourse-sonarqube-resource/issues/11)]

## [0.0.30] - 2018-01-18

### Added
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ RUN mvn -q org.apache.maven.plugins:maven-dependency-plugin:3.0.2:get \
ENV PATH="/usr/local/bin:/usr/bin:/bin"

LABEL maintainer="[email protected]" \
version="0.0.30"
version="0.0.31"

COPY ./assets/* /opt/resource/

Expand Down
12 changes: 10 additions & 2 deletions assets/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function read_properties {

# Checks on a compute engine task
# Params:
# $1 - Username or Access token, a colon ans optional the password, e.g. "user:password" (required)
# $1 - Username or Access token, a colon and optional the password, e.g. "user:password" (required)
# $2 - SonarQube URL. Must end with a slash (required)
# $3 - CE Task ID (required)
function sq_ce_task {
Expand All @@ -26,9 +26,17 @@ function sq_ce_task {

# Checks the quality gate status of a project
# Params:
# $1 - Username or Access token, a colon ans optional the password, e.g. "user:password" (required)
# $1 - Username or Access token, a colon and optional the password, e.g. "user:password" (required)
# $2 - SonarQube URL. Must end with a slash (required)
# $3 - Analysis ID (required)
function sq_qualitygates_project_status {
curl -s -L -u "${1}" "${2}api/qualitygates/project_status?analysisId=${3}"
}

# Retrieves the version of a SonarQube server instance
# Params:
# $1 - Username or Access token, a colon and optional the password, e.g. "user:password" (required)
# $2 - SonarQube URL. Must end with a slash (required)
function sq_server_version {
curl -s -L -u "${1}" "${2}api/server/version"
}
6 changes: 6 additions & 0 deletions assets/out
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ eval "${scanner_bin} ${scanner_opts}"
echo "Reading SonarQube scanner report (${scanner_report_file})..."
if [ -f "${scanner_report_file}" ]; then
eval "$(read_properties "${scanner_report_file}")"
if [ -z "${serverVersion:-}" ]; then
# Older versions of SonarQube don't store the serverVersion in
# sonar-report.txt. There is a REST API though, that can be used
# to fetch the version.
serverVersion="$(sq_server_version "${sonar_login}":"${sonar_password}" "${sonar_host_url}")"
fi
else
echo "error: SonarQube report could not be located."
exit 1
Expand Down

0 comments on commit d7b389e

Please sign in to comment.