Automatically remove Sonarqube branch projects when git branch merged / removed

与世无争的帅哥 提交于 2019-12-22 04:32:11

问题


We currently have a jenkins pipeline using Multibranch Workflow plugin. Each git branch execute a sonarqube analysis creating a sonarqube project using the sonar.branch property. This is very useful because each branch is being analyzed before merge it, the problem appear when a branch is merged with master and disappear on GIT, the project continues on sonarqube and need to be deleted manually. Is There a way to do it automatically? or any other recomendation?


回答1:


You can define a method as below, to do the job and then call the method whenever you need according to your need or on some event like git branch merged/removed, etc.

def deleteSonarProject() {
    def sonarToken = "-your admin credential token generate it from sonarServer-"
    def url = "http://yourBaseURL:portNumber/api/projects/delete"
    sh "curl -u ${sonarToken}: ${url} -d 'project=projectKey'"
}



回答2:


The best way to remove SonarQube branch projects is to not push them to the server in the first place. Here are your options:

  • use SonarLint to spot issues directly in your IDE
  • if you're using GitHub, use the GitHub Plugin
  • if you're using BitBucket, use this plugin or this one

At SonarSource, we use SonarLint and the GitHub Plugin on a daily basis. One last solution is to delete manually the project using the api/projects/delete web service.




回答3:


If you happen to be using Bitbucket Server and the Sonar for Bitbucket Server add-on, there's an automatic way to perform this cleanup. To enable this setting from Bitbucket Server, follow the 3 steps shown in the screenshots below.

Screenshot of 3 steps



来源:https://stackoverflow.com/questions/38221149/automatically-remove-sonarqube-branch-projects-when-git-branch-merged-removed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!