Loading templates/gitlab-ci-sonar.yml +14 −6 Original line number Diff line number Diff line Loading @@ -410,11 +410,18 @@ stages: fi } # determines whether the given SonarQube param is defined # either in the sonar-project.properties or in the $SONAR_BASE_ARGS variable function has_sonar_param() { # extract the value of a SonarQube param # either from the sonar-project.properties or from the $SONAR_BASE_ARGS variable function get_sonar_param() { sonar_param="$1" grep -e "^sonar\.${sonar_param}[ \t]*[:=]" sonar-project.properties > /dev/null || echo "$SONAR_BASE_ARGS" | grep -e "-Dsonar\.${sonar_param}=" > /dev/null # first try to get it from sonar-project.properties if grep -e "^sonar\.${sonar_param}[ \t]*[:=]" sonar-project.properties > /dev/null 2>&1 then sed -n "s/^[ \t]*sonar\.${sonar_param}[ \t]*[:=][ \t]*\"\?\([^ \t\r\n\"]*\).*/\1/p" sonar-project.properties else # if not found, try to get it from SONAR_BASE_ARGS echo "$SONAR_BASE_ARGS" | sed -n "s/.*-Dsonar\.${sonar_param}=\"\?\([^ \t\r\n\"]*\).*/\1/p" fi } unscope_variables Loading Loading @@ -445,14 +452,14 @@ sonar: - eval_java_proxy_args script: - | if [[ -z "$SONAR_PROJECT_KEY" ]] && ! has_sonar_param projectKey if [[ -z "$SONAR_PROJECT_KEY" ]] && [[ -z "$(get_sonar_param projectKey)" ]] then log_info "No Sonar Project Key explicitly set: use default \\e[33;1m$CI_PROJECT_PATH_SLUG\\e[0m" log_info "If you want another value, either set the 'sonar.projectKey' entry in your sonar-project.properties, or set it as \$SONAR_PROJECT_KEY" export SONAR_PROJECT_KEY="$CI_PROJECT_PATH_SLUG" fi - | if [[ -z "$SONAR_PROJECT_NAME" ]] && ! has_sonar_param projectName if [[ -z "$SONAR_PROJECT_NAME" ]] && [[ -z "$(get_sonar_param projectName)" ]] then log_info "No Sonar Project Name explicitly set: use default \\e[33;1m$CI_PROJECT_PATH\\e[0m" log_info "If you want another value, either set the 'sonar.projectName' entry in your sonar-project.properties, or set it as \$SONAR_PROJECT_NAME" Loading Loading @@ -490,6 +497,7 @@ sonar: - | if [[ "$SONAR_QUALITY_GATE_ENABLED" == "true" ]] then SONAR_PROJECT_KEY=${SONAR_PROJECT_KEY:-$(get_sonar_param projectKey)} log_info "Retrieve GitLab SAST report from SonarQube for project \\e[33;1m${SONAR_PROJECT_KEY}\\e[0m..." mkdir -p ./reports sonar_api_params="projectKey=$SONAR_PROJECT_KEY" Loading Loading
templates/gitlab-ci-sonar.yml +14 −6 Original line number Diff line number Diff line Loading @@ -410,11 +410,18 @@ stages: fi } # determines whether the given SonarQube param is defined # either in the sonar-project.properties or in the $SONAR_BASE_ARGS variable function has_sonar_param() { # extract the value of a SonarQube param # either from the sonar-project.properties or from the $SONAR_BASE_ARGS variable function get_sonar_param() { sonar_param="$1" grep -e "^sonar\.${sonar_param}[ \t]*[:=]" sonar-project.properties > /dev/null || echo "$SONAR_BASE_ARGS" | grep -e "-Dsonar\.${sonar_param}=" > /dev/null # first try to get it from sonar-project.properties if grep -e "^sonar\.${sonar_param}[ \t]*[:=]" sonar-project.properties > /dev/null 2>&1 then sed -n "s/^[ \t]*sonar\.${sonar_param}[ \t]*[:=][ \t]*\"\?\([^ \t\r\n\"]*\).*/\1/p" sonar-project.properties else # if not found, try to get it from SONAR_BASE_ARGS echo "$SONAR_BASE_ARGS" | sed -n "s/.*-Dsonar\.${sonar_param}=\"\?\([^ \t\r\n\"]*\).*/\1/p" fi } unscope_variables Loading Loading @@ -445,14 +452,14 @@ sonar: - eval_java_proxy_args script: - | if [[ -z "$SONAR_PROJECT_KEY" ]] && ! has_sonar_param projectKey if [[ -z "$SONAR_PROJECT_KEY" ]] && [[ -z "$(get_sonar_param projectKey)" ]] then log_info "No Sonar Project Key explicitly set: use default \\e[33;1m$CI_PROJECT_PATH_SLUG\\e[0m" log_info "If you want another value, either set the 'sonar.projectKey' entry in your sonar-project.properties, or set it as \$SONAR_PROJECT_KEY" export SONAR_PROJECT_KEY="$CI_PROJECT_PATH_SLUG" fi - | if [[ -z "$SONAR_PROJECT_NAME" ]] && ! has_sonar_param projectName if [[ -z "$SONAR_PROJECT_NAME" ]] && [[ -z "$(get_sonar_param projectName)" ]] then log_info "No Sonar Project Name explicitly set: use default \\e[33;1m$CI_PROJECT_PATH\\e[0m" log_info "If you want another value, either set the 'sonar.projectName' entry in your sonar-project.properties, or set it as \$SONAR_PROJECT_NAME" Loading Loading @@ -490,6 +497,7 @@ sonar: - | if [[ "$SONAR_QUALITY_GATE_ENABLED" == "true" ]] then SONAR_PROJECT_KEY=${SONAR_PROJECT_KEY:-$(get_sonar_param projectKey)} log_info "Retrieve GitLab SAST report from SonarQube for project \\e[33;1m${SONAR_PROJECT_KEY}\\e[0m..." mkdir -p ./reports sonar_api_params="projectKey=$SONAR_PROJECT_KEY" Loading