Skip to content

Commit 00b6e4c

Browse files
committed
configure project default visibility
1 parent 0e75b8e commit 00b6e4c

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

sonarqube/configure.sh

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ if [ -z "${authTokenVerified}" ]; then
279279
fi
280280
fi
281281

282+
if [ -n "${VALUES_WRITTEN_TO_CONFIG}" ]; then
283+
echo_warn "Some values in '${ODS_CONFIGURATION_DIR}/ods-core.env' have been updated."
284+
echo_warn "Commit and push the changes to Bitbucket."
285+
fi
286+
282287
# Create and configure a quality gate and make it default.
283288
echo_info "Ensuring quality gate 'ODS Default Quality Gate' exists and is set as default ..."
284289
GATE_NAME="ODS Default Quality Gate"
@@ -395,9 +400,28 @@ if true; then
395400
fi
396401
fi
397402

398-
if [ -n "${VALUES_WRITTEN_TO_CONFIG}" ]; then
399-
echo_warn "Some values in '${ODS_CONFIGURATION_DIR}/ods-core.env' have been updated."
400-
echo_warn "Commit and push the changes to Bitbucket."
403+
# New: update default project visibility to 'private' when configured
404+
configured_visibility=""
405+
if [ -f "${ODS_CONFIGURATION_DIR}/ods-core.env" ]; then
406+
configured_visibility=$(grep -E '^SONAR_SCAN_PROJECTS_PRIVATE=' "${ODS_CONFIGURATION_DIR}/ods-core.env" | cut -d"=" -f2- | tr -d '\r' | tr -d '"' | tr -d ' ' || echo "")
407+
fi
408+
409+
if [ "${configured_visibility}" = "true" ]; then
410+
echo_info "SONAR_SCAN_PROJECTS_PRIVATE='true' — setting default project visibility to 'private' ..."
411+
if curl ${INSECURE} -sS -X POST --user "${ADMIN_USER_NAME}:${ADMIN_USER_PASSWORD}" \
412+
"${SONARQUBE_URL}/api/projects/update_default_visibility?projectVisibility=private"; then
413+
echo_info "Default project visibility set to 'private'."
414+
else
415+
echo_warn "Failed to set default project visibility to 'private'."
416+
fi
417+
else
418+
echo_info "SONAR_SCAN_PROJECTS_PRIVATE is not 'true' (value: '${configured_visibility}') setting default project visibility to 'public'."
419+
if curl ${INSECURE} -sS -X POST --user "${ADMIN_USER_NAME}:${ADMIN_USER_PASSWORD}" \
420+
"${SONARQUBE_URL}/api/projects/update_default_visibility?projectVisibility=public"; then
421+
echo_info "Default project visibility set to 'public'."
422+
else
423+
echo_warn "Failed to set default project visibility to 'public'."
424+
fi
401425
fi
402426

403427
echo_done "SonarQube configured."

0 commit comments

Comments
 (0)