diff --git a/.buildkite/pipeline.json.py b/.buildkite/pipeline.json.py index 1840d5dc9c..790add24cf 100755 --- a/.buildkite/pipeline.json.py +++ b/.buildkite/pipeline.json.py @@ -37,6 +37,8 @@ def main(): ".buildkite/pipelines/send_email_notification.sh")) pipeline_steps.append(pipeline_steps.generate_step("Upload clang-format validation", ".buildkite/pipelines/format_and_validation.yml.sh")) + pipeline_steps.append(pipeline_steps.generate_step("Scan and upload SonarQube report", + ".buildkite/pipelines/sonarqube.yml.sh")) config = buildConfig.Config() config.parse() if config.build_windows: diff --git a/.buildkite/pipelines/sonarqube.yml.sh b/.buildkite/pipelines/sonarqube.yml.sh new file mode 100755 index 0000000000..312d293d87 --- /dev/null +++ b/.buildkite/pipelines/sonarqube.yml.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +# or more contributor license agreements. Licensed under the Elastic License +# 2.0 and the following additional limitation. Functionality enabled by the +# files subject to the Elastic License 2.0 may only be used in production when +# invoked by an Elasticsearch process with a license key installed that permits +# use of machine learning features. You may not use this file except in +# compliance with the Elastic License 2.0 and the foregoing additional +# limitation. + +cat </dev/null + +# SonarQube project analyse token was provided +if [[ -z "${SONAR_LOGIN}" ]]; then + echo "No SONAR_LOGIN token was provided, attempting to resolve it via vault..." + + if [[ -z "${VAULT_ADDR}" ]]; + then + echo "VAULT_ADDR is missing." + exit 1 + fi + if [[ -z "${VAULT_TOKEN}" ]]; + then + echo "A VAULT_TOKEN is missing for ${VAULT_ADDR}." + exit 1 + fi + if [[ -z "${VAULT_SONAR_TOKEN_PATH}" ]]; + then + echo "VAULT_SONAR_TOKEN_PATH is missing." + exit 1 + fi + + if [[ "$VAULT_SONAR_TOKEN_PATH" =~ ^kv/* ]]; + then + SONAR_LOGIN=$(vault kv get --field token "${VAULT_SONAR_TOKEN_PATH}") + else + SONAR_LOGIN=$(vault read --field token "${VAULT_SONAR_TOKEN_PATH}") + fi +fi + +echo "Running sonar-scanner" +runScanner diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000000..79f6e9cc8c --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,16 @@ +# must be unique in a given SonarQube instance +sonar.projectKey=elastic_ml-cpp_271ade36-31fc-4c6b-966e-80245560ad14 + +# Encoding of the source code. Default is default system encoding +sonar.sourceEncoding=UTF-8 +sonar.cfamily.compile-commands=cmake-build-docker/compile_commands.json + +sonar.host.url=https://sonar.elastic.dev +sonar.sources= ./bin,./lib,./include,./devbin +sonar.language=cpp +sonar.inclusions = **/*.cc,**/*.h +sonar.lang.patterns.cpp=**/*.cc,**/*.h +sonar.lang.patterns.c=**/*.c + +# Disable SCM Blame information +sonar.scm.disabled=true