如何将 Sonar Quality Gates 与 Gitlab

编程入门 行业动态 更新时间:2024-10-11 09:19:28
本文介绍了如何将 Sonar Quality Gates 与 Gitlab-CI 集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 gitlab-ci 集成,需要进行声纳分析,如果质量门通过,则构建 docker 映像.

I have a gitlab-ci integration that require a sonar analysis and if the quality gates pass, to build a docker image.

这可以使用 gitlab-ci 吗?

Is this possible using gitlab-ci ?

推荐答案

为失败的质量门中断 CI 构建,

To break the CI build for a failed Quality Gate,

1.在/report-task.txt 中搜索 CE 任务 URL (ceTaskUrl) 和 CE 的值任务 ID (ceTaskId)

1.Search in /report-task.txt the values of the CE Task URL (ceTaskUrl) and CE Task Id (ceTaskId)

2.Call/api/ce/task?id=XXX 其中 XXX 是从步骤 1 中检索到的 CE 任务 ID例如:- /api/ce/task?id=Your ceTaskId

2.Call /api/ce/task?id=XXX where XXX is the CE Task Id retrieved from step 1 Ex:- /api/ce/task?id=Your ceTaskId

3.等待一段时间,直到第 2 步的状态为 SUCCESS、CANCELED 或 FAILED

3.Wait for sometime until the status is SUCCESS, CANCELED or FAILED from Step 2

4.如果失败,则中断构建(此处失败无法生成声纳报告)

4.If it is FAILED, break the build (Here failure is unable to generate sonar report)

5.如果成功,则使用/api/ce/task 返回的 JSON 中的 analysisId?id=XXX(step2)并立即调用/api/qualitygates/project_status?analysisId=YYY检查质量门的状态.例如:- /api/qualitygates/project_status?analysisId=Your分析ID

5.If successful,then Use the analysisId from the JSON returned by /api/ce/task? id=XXX(step2)and Immediately call /api/qualitygates/project_status?analysisId=YYY to check the status of the quality gate. Ex:- /api/qualitygates/project_status?analysisId=Your analysisId

6.Step 5给出关键、主要和次要错误阈值限制的状态

6.Step 5 gives the status of the critical, major and minor error threshold limit

7.基于极限破建.

build: stage: build before_script: - yum -y install epel-release - yum -y install jq - yum install -y coreutils script: - mvn sonar:sonar -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_LOGIN_TOKEN -Dsonar.working.directory=../target/.sonar - export url=$(cat ../target/.sonar/report-task.txt | grep ceTaskUrl | cut -c11- ) #URL where report gets stored - sleep 15s #Wait time for the report - curl -k -u "$SONAR_LOGIN_TOKEN":"" $url -o analysis.txt - export status=$(cat analysis.txt | jq -r '.task.status') #Status as SUCCESS, CANCELED or FAILED - export analysisId=$(cat analysis.txt | jq -r '.task.analysisId') #Get the analysis Id - | if [ "$status" == "SUCCESS" ];then echo -e "SONAR ANALYSIS SUCCESSFUL...ANALYSING RESULTS"; curl -k -u "$SONAR_LOGIN_TOKEN":"" yourSonarURI/api/qualitygates/project_status?analysisId=$analysisId -o result.txt; #Analysis result like critical, major and minor issues export result=$(cat result.txt | jq -r '.projectStatus.status'); if [ "$result" == "ERROR" ];then echo -e "91mSONAR RESULTS FAILED"; echo "$(cat result.txt | jq -r '.projectStatus.conditions')"; #prints the critical, major and minor violations exit 1 #breaks the build for violations else echo -e "SONAR RESULTS SUCCESSFUL"; echo "$(cat result.txt | jq -r '.projectStatus.conditions')"; exit 0 fi else echo -e "e[91mSONAR ANALYSIS FAILEDe[0m"; exit 1 #breaks the build for failure in Step2 fi

更多推荐

如何将 Sonar Quality Gates 与 Gitlab

本文发布于:2023-11-15 22:23:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1598481.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   Sonar   Quality   Gates   Gitlab

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!