diff --git a/CHANGELOG.md b/CHANGELOG.md index e793cec..33749dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ([#19](https://github.com/cathive/concourse-sonarqube-resource/issues/19)) - Docker builds should no longer fail because of corrupted sonar-scanner zip archive. ([#26](https://github.com/cathive/concourse-sonarqube-resource/issues/26)) +- Anonymous access to SonarQube servers that don't require authentication + should now be possible. ([#25](https://github.com/cathive/concourse-sonarqube-resource/issues/25)) ### Added diff --git a/assets/in b/assets/in index 9202fb4..02ac881 100755 --- a/assets/in +++ b/assets/in @@ -30,13 +30,16 @@ if [[ -z "${sonar_host_url}" ]]; then fi sonar_login=$(jq -r '.source.login // ""' < "${payload}") -if [[ -z "${sonar_login}" ]]; then - echo "sonar_login param has not been specified." - exit 1 -fi sonar_password=$(jq -r '.source.password // ""' < "${payload}") +if [[ ! -z "${sonar_login}" ]] && [[ "${sonar_login}" != "" ]]; then + sonar_token="${sonar_login}" + if [[ ! -z "${sonar_password}" ]] && [[ "${sonar_password}" != "" ]]; then + sonar_token+=":${sonar_password}" + fi +fi + ce_task_id=$(jq -r '.version.ce_task_id // ""' < "${payload}") if [[ -z "${ce_task_id}" ]]; then echo "version to fetch cannot be determined: ce_task_id not set?" @@ -48,7 +51,7 @@ cd "${dest}" ce_task_info="./ce_task.json" ce_task_status="PENDING" until [ "${ce_task_status}" != "PENDING" ] && [ "${ce_task_status}" != "IN_PROGRESS" ]; do - sq_ce_task "${sonar_login}:${sonar_password}" "${sonar_host_url}" "${ce_task_id}" > "${ce_task_info}" + sq_ce_task "${sonar_token}" "${sonar_host_url}" "${ce_task_id}" > "${ce_task_info}" ce_task_status=$(jq -r '.task.status // ""' < "${ce_task_info}") if [[ "${ce_task_status}" != "PENDING" ]] && [[ "${ce_task_status}" != "IN_PROGRESS" ]]; then echo "Waiting for compute engine result (sleep: 5s)..." @@ -66,7 +69,7 @@ if [[ "${ce_task_status}" == "SUCCESS" ]]; then fi project_status="./qualitygate_project_status.json" -sq_qualitygates_project_status "${sonar_login}:${sonar_password}" "${sonar_host_url}" "${analysis_id}" > "${project_status}" +sq_qualitygates_project_status "${sonar_token}" "${sonar_host_url}" "${analysis_id}" > "${project_status}" project_status=$(jq -r '.projectStatus.status // ""' < "${project_status}") diff --git a/assets/out b/assets/out index 3ac5015..fac0853 100755 --- a/assets/out +++ b/assets/out @@ -199,7 +199,14 @@ if [[ -f "${scanner_report_file}" ]]; then # Older versions of SonarQube don't store the serverVersion in # report-task.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}")" + sonar_token="" + if [[ ! -z "${sonar_login}" ]] && [[ "${sonar_login}" != "" ]]; then + sonar_token="${sonar_login}" + if [[ ! -z "${sonar_password}" ]] && [[ "${sonar_password}" != "" ]]; then + sonar_token+=":${sonar_password}" + fi + fi + serverVersion="$(sq_server_version "${sonar_token}" "${sonar_host_url}")" fi else echo "error: SonarQube report could not be located."