git 分支合并/移除时自动移除 Sonarqube 分支项目 [英] Automatically remove Sonarqube branch projects when git branch merged / removed
问题描述
我们目前有一个使用 Multibranch Workflow 插件
的 jenkins 管道.每个 git 分支执行一个 sonarqube 分析,使用 sonar.branch
属性创建一个 sonarqube 项目.这非常有用,因为在合并之前正在分析每个分支,当分支与 master 合并并在 GIT 上消失时会出现问题,项目在 sonarqube 上继续,需要手动删除.有没有办法自动完成?或任何其他建议?
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?
推荐答案
你可以定义一个方法如下,来完成这项工作,然后根据你的需要或在某些事件(如 git branch merge/)时随时调用该方法删除等.
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'"
}
这篇关于git 分支合并/移除时自动移除 Sonarqube 分支项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!