diff --git a/README.md b/README.md index cfb5d4e5549d8b27e0d61113732acce9d1852188..69aac89b4a52d646712d26b9316d3bf065ab3e33 100644 --- a/README.md +++ b/README.md @@ -81,11 +81,11 @@ It is bound to the `test` stage, and uses the following variables: | Name | description | default value | | ------------------------ | -------------------------------------- | ----------------- | -| `SONAR_URL` | SonarQube server url | _none_ (disabled) | +| `SONAR_HOST_URL` | SonarQube server url | _none_ (disabled) | | :lock: `SONAR_AUTH_TOKEN`| SonarQube authentication [token](https://docs.sonarqube.org/latest/user-guide/user-token/) (depends on your authentication method) | _none_ | | :lock: `SONAR_LOGIN` | SonarQube login (depends on your authentication method) | _none_ | | :lock: `SONAR_PASSWORD` | SonarQube password (depends on your authentication method) | _none_ | -| `SONAR_BASE_ARGS` | SonarQube [analysis arguments](https://docs.sonarqube.org/latest/analysis/analysis-parameters/) | `sonar:sonar -Dsonar.host.url=${SONAR_URL} -Dsonar.links.homepage=${CI_PROJECT_URL} -Dsonar.links.ci=${CI_PROJECT_URL}/-/pipelines -Dsonar.links.issue=${CI_PROJECT_URL}/-/issues` | +| `SONAR_BASE_ARGS` | SonarQube [analysis arguments](https://docs.sonarqube.org/latest/analysis/analysis-parameters/) | `sonar:sonar -Dsonar.links.homepage=${CI_PROJECT_URL} -Dsonar.links.ci=${CI_PROJECT_URL}/-/pipelines -Dsonar.links.issue=${CI_PROJECT_URL}/-/issues` | | :lock: `SONAR_GITLAB_TOKEN` | GitLab [access token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html) with `api` scope. When set, activates the [Sonar GitLab plugin](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/#plugins-properties) integration. | _none_ | | `SONAR_BRANCH_ANALYSIS_DISABLED` | Set to `true` to disable automatic [Pull Request Analysis](https://docs.sonarqube.org/latest/analysis/pull-request/) and [Branch Analysis](https://docs.sonarqube.org/latest/branches/overview/) | _none_ (enabled) | | `SONAR_GITLAB_ARGS` | Extra arguments to use with [Sonar GitLab plugin](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/#plugins-properties) | `-Dsonar.gitlab.url=${CI_SERVER_URL} -Dsonar.gitlab.user_token=${SONAR_GITLAB_TOKEN} -Dsonar.gitlab.project_id=${CI_PROJECT_ID} -Dsonar.gitlab.commit_sha=${CI_COMMIT_SHA} -Dsonar.gitlab.ref_name=${CI_COMMIT_REF_NAME}` | diff --git a/kicker.json b/kicker.json index b3bbba3c40e780f462358f20cacf309d37b72707..617b8ef68c2d53c0df806569660aae6d439ec642 100644 --- a/kicker.json +++ b/kicker.json @@ -47,7 +47,7 @@ "description": "Code quality and security analysis with [SONARQube](https://www.sonarqube.org/)", "variables": [ { - "name": "SONAR_URL", + "name": "SONAR_HOST_URL", "type": "url", "description": "SonarQube server url", "mandatory": true @@ -70,10 +70,10 @@ { "name": "SONAR_BASE_ARGS", "description": "SonarQube [analysis arguments](https://docs.sonarqube.org/latest/analysis/analysis-parameters/)", - "default": "sonar:sonar -Dsonar.host.url=${SONAR_URL} -Dsonar.links.homepage=${CI_PROJECT_URL} -Dsonar.links.ci=${CI_PROJECT_URL}/-/pipelines -Dsonar.links.issue=${CI_PROJECT_URL}/-/issues", + "default": "sonar:sonar -Dsonar.links.homepage=${CI_PROJECT_URL} -Dsonar.links.ci=${CI_PROJECT_URL}/-/pipelines -Dsonar.links.issue=${CI_PROJECT_URL}/-/issues", "advanced": true }, - { + { "name": "SONAR_GITLAB_TOKEN", "description": "GitLab API access token. When set, activates the [Sonar GitLab plugin](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/#plugins-properties) integration, and enables SonarQube [Pull Request Analysis](https://docs.sonarqube.org/latest/analysis/pull-request/)", "secret": true diff --git a/templates/gitlab-ci-maven.yml b/templates/gitlab-ci-maven.yml index fce0414c35cc0fe77bd27a043ce76aa3faeb3fff..24f23fd9a3a791df93f5863caaf7ac6f763ab5ff 100644 --- a/templates/gitlab-ci-maven.yml +++ b/templates/gitlab-ci-maven.yml @@ -86,7 +86,6 @@ variables: # default uses branch analysis: https://docs.sonarqube.org/latest/branches/overview/ SONAR_BASE_ARGS: >- sonar:sonar - -Dsonar.host.url=${SONAR_URL} -Dsonar.links.homepage=${CI_PROJECT_URL} -Dsonar.links.ci=${CI_PROJECT_URL}/-/pipelines -Dsonar.links.issue=${CI_PROJECT_URL}/-/issues @@ -501,12 +500,18 @@ mvn-sonar: GIT_DEPTH: 0 script: - sonar_autodetect_mr + - | + if [[ "$SONAR_URL" ]] && [[ -z "$SONAR_HOST_URL" ]] + then + log_warn '$SONAR_URL variable defined: use $SONAR_HOST_URL instead (see doc)' + export SONAR_HOST_URL="$SONAR_URL" + fi - if [[ "$SONAR_GITLAB_TOKEN" ]]; then sonar_extra_args="$SONAR_GITLAB_ARGS"; fi - mvn ${TRACE+-Dsonar.verbose=true} $MAVEN_CLI_OPTS $mvn_settings_opt $java_proxy_args ${SONAR_AUTH_TOKEN+-Dsonar.login=$SONAR_AUTH_TOKEN} ${SONAR_LOGIN+-Dsonar.login=$SONAR_LOGIN} ${SONAR_PASSWORD+-Dsonar.password=$SONAR_PASSWORD} $SONAR_BASE_ARGS $sonar_extra_args $sonar_mr_args - if [[ "$SONAR_QUALITY_GATE_ENABLED" == "true" ]]; then sonar_quality_gate_check; fi rules: - # exclude if $SONAR_URL not set - - if: '$SONAR_URL == null || $SONAR_URL == ""' + # exclude if $SONAR_URL and $SONAR_HOST_URL not set + - if: '($SONAR_HOST_URL == null || $SONAR_HOST_URL == "") && ($SONAR_URL == null || $SONAR_URL == "")' when: never - !reference [.test-policy, rules]