Skip to content

Commit

Permalink
ci: use pysonar-scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
henryborchers committed Nov 1, 2024
1 parent 69859f7 commit dd2bc14
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
29 changes: 25 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -899,20 +899,41 @@ pipeline {
equals expected: true, actual: params.USE_SONARQUBE
beforeOptions true
}
environment{
UV_INDEX_STRATEGY='unsafe-best-match'
SONAR_SCANNER_HOME='/tmp/sonar'
UV_TOOL_DIR='/tmp/uvtools'
UV_PYTHON_INSTALL_DIR='/tmp/uvpython'
UV_CACHE_DIR='/tmp/uvcache'
}
steps{
script{
def props = readTOML( file: 'pyproject.toml')['project']
withSonarQubeEnv(installationName:'sonarcloud', credentialsId: SONARQUBE_CREDENTIAL_ID) {
if (env.CHANGE_ID){
sh(
label: 'Running Sonar Scanner',
script: "sonar-scanner -Dsonar.projectVersion=${props.version} -Dsonar.buildString=\"${env.BUILD_TAG}\" -Dsonar.pullrequest.key=${env.CHANGE_ID} -Dsonar.pullrequest.base=${env.CHANGE_TARGET} -Dsonar.cfamily.cache.enabled=false -Dsonar.cfamily.threads=\$(grep -c ^processor /proc/cpuinfo) -Dsonar.cfamily.build-wrapper-output=build/build_wrapper_output_directory"
)
script: """python3 -m venv uv
uv/bin/pip install uv
trap "rm -rf uv" EXIT
uv/bin/uv venv venv
trap "rm -rf uv && rm -rf venv" EXIT
. ./venv/bin/activate
uv/bin/uv pip install uv
uv tool run pysonar-scanner -Dsonar.projectVersion=${props.version} -Dsonar.buildString=\"${env.BUILD_TAG}\" -Dsonar.pullrequest.key=${env.CHANGE_ID} -Dsonar.pullrequest.base=${env.CHANGE_TARGET} -Dsonar.cfamily.cache.enabled=false -Dsonar.cfamily.threads=\$(grep -c ^processor /proc/cpuinfo) -Dsonar.cfamily.build-wrapper-output=build/build_wrapper_output_directory
"""
)
} else {
sh(
label: 'Running Sonar Scanner',
script: "sonar-scanner -Dsonar.projectVersion=${props.version} -Dsonar.buildString=\"${env.BUILD_TAG}\" -Dsonar.branch.name=${env.BRANCH_NAME} -Dsonar.cfamily.cache.enabled=false -Dsonar.cfamily.threads=\$(grep -c ^processor /proc/cpuinfo) -Dsonar.cfamily.build-wrapper-output=build/build_wrapper_output_directory"
)
script: """python3 -m venv uv
uv/bin/pip install uv
uv/bin/uv venv venv
. ./venv/bin/activate
uv/bin/uv pip install uv
uv tool run pysonar-scanner -Dsonar.projectVersion=${props.version} -Dsonar.buildString=\"${env.BUILD_TAG}\" -Dsonar.branch.name=${env.BRANCH_NAME} -Dsonar.cfamily.cache.enabled=false -Dsonar.cfamily.threads=\$(grep -c ^processor /proc/cpuinfo) -Dsonar.cfamily.build-wrapper-output=build/build_wrapper_output_directory
"""
)
}
}
timeout(time: 1, unit: 'HOURS') {
Expand Down
14 changes: 0 additions & 14 deletions ci/docker/linux/jenkins/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ ARG SONAR_SCANNER_VERSION
ARG SONAR_SCANNER_HOME=/opt/sonar/${SONAR_SCANNER_VERSION}-linux
ENV SONAR_USER_HOME=/opt/sonar/.sonar

RUN curl --create-dirs -sSLo /tmp/sonar-scanner.zip \
https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux.zip && \
unzip -o /tmp/sonar-scanner.zip -d /opt/sonar/ && \
rm /tmp/sonar-scanner.zip && \
mkdir -p ${SONAR_USER_HOME}/cache && \
chmod -R 777 "${SONAR_USER_HOME}" &&\
ln -s /opt/sonar/sonar-scanner-${SONAR_SCANNER_VERSION}-linux/bin/sonar-scanner /usr/local/bin/sonar-scanner && \
which sonar-scanner


RUN curl --create-dirs -sSLo /tmp/build-wrapper-linux-x86.zip https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip && \
unzip -o /tmp/build-wrapper-linux-x86.zip -d /opt/ && \
ln -s /opt/build-wrapper-linux-x86/build-wrapper-linux-x86-64 /usr/local/bin/build-wrapper-linux-x86-64 && \
Expand All @@ -80,14 +70,10 @@ RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

COPY --from=SONAR_BUILDER /opt/sonar /opt/sonar/
COPY --from=SONAR_BUILDER /opt/build-wrapper-linux-x86 /opt/build-wrapper-linux-x86/
ARG SONAR_SCANNER_VERSION
ARG SONAR_SCANNER_HOME=/opt/sonar/${SONAR_SCANNER_VERSION}-linux
ENV SONAR_USER_HOME=/opt/sonar/.sonar

RUN ln -s /opt/sonar/sonar-scanner-${SONAR_SCANNER_VERSION}-linux/bin/sonar-scanner /usr/local/bin/sonar-scanner && \
which sonar-scanner

RUN ln -s /opt/build-wrapper-linux-x86/build-wrapper-linux-x86-64 /usr/local/bin/build-wrapper-linux-x86-64 && \
which build-wrapper-linux-x86-64
Expand Down

0 comments on commit dd2bc14

Please sign in to comment.