在Jenkinsfile中设置SonarQube Webhook [英] Set a SonarQube webhook in Jenkinsfile

查看:742
本文介绍了在Jenkinsfile中设置SonarQube Webhook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个Jenkins多分支管道,在每次向位桶推送时,都会在该项目的那个分支上执行SonarQube分析. Jenkins正确地为每个分支创建了新作业,并在SonarQube中创建了一个新项目,在分支名称后附加了项目名称.

I'm trying to create a Jenkins multibranch pipeline where on every push to bitbucket, a SonarQube analysis is performed on that branch of the project. Jenkins correctly creates the new job for each branch and a new project is created in SonarQube with the branch name appended to the project name.

我遇到的问题是,当SonarQube创建新项目时,默认情况下未设置报告质量门状态的webhook,因此我必须手动进入每个SonarQube项目并设置Webhook url.当我的团队每天建立许多分支机构时,这就是一个问题.

The issue I'm having is that when SonarQube creates the new project, the webhook to report the Quality Gate status is not set by default, so I have to manually go into each SonarQube project and set the Webhook url. This is an issue when my team makes many branches a day.

是否可以在Jenksfile中指定我希望SonarQube项目具有Webhook?

Is there a way to specify in my Jenksfile that I want the SonarQube project to have a webhook?

stage('SonarQube Analysis') {
        steps {
            withSonarQubeEnv('Sonarqube Server') {
                script {
                    def sonarScanner = tool name: 'SonarQube Scanner', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
                    sh "${sonarScanner}/bin/sonar-scanner " +
                    "-Dsonar.projectKey=ProjectName-${GIT_BRANCH} " +
                    "-Dsonar.projectName=ProjectName-${GIT_BRANCH} " +
                    "-Dsonar.projectVersion=0.0.0 " +
                    "-Dsonar.sources=**/src " +
                    "-Dsonar.java.binaries=**/build " +
                    "-Dsonar.exclusions=excluded_dirs/** " +
                    "-Dsonar.sourceEncoding=UTF-8"
                }
            }
            timeout(time: 5, unit: 'MINUTES') {
                script {
                    def qg = waitForQualityGate()
                    if (qg.status != 'OK') {
                        error "Pipeline aborted due to a quality gate failure: ${qg.status}"
                    }
                }
            }
        }
    }

当前,我的Jenkins生成文件在5分钟后超时.设置了Webhook后,需要几秒钟的时间才能听到回音.我的webhook网址是正确的,我只希望Jenkinsfile设置它,而不是手动设置.

Currently, my Jenkins build times out after 5 minutes. When the webhook is set, it takes a few seconds to hear back. My webhook url is correct, I just want the Jenkinsfile to set it, not me manually.

不幸的是,我不是SonarQube的管理员,只有我的项目

Unfortunately, I am not an admin in SonarQube, only my projects

推荐答案

以sonarqube中的管理员身份,转到https://my-sonarqube.tld/admin/webhooks 将网址配置为https://my-jenkins-domain.tld/sonarqube-webhook/

As admin in sonarqube, go to https://my-sonarqube.tld/admin/webhooks configure the url to be https://my-jenkins-domain.tld/sonarqube-webhook/

然后这将适用于所有项目.如果您仍未收到交货,请检查最近的交货(在同一页面中的选项)并查看错误.

This should then apply to all projects. If you are still not receiving deliveries, check recent deliveries (option in same page) and view error.

您的詹金斯将需要具有有效的证书才能建立安全连接

Your jenkins will need to have a valid certificate for a secure connection to be established

另请参见: https://docs.sonarqube.org/latest/project -administration/webhooks/

或者,您可以为项目的每次调用/扫描设置一个Webhook. 在cli -Dsonar.webhooks.project=https://my-jenkins-domain.tld/sonarqube-webhook/或sonar-project.properties onar.webhooks.project=https://my-jenkins-domain.tld/sonarqube-webhook/

Alternatively, you can set a webhook per invocation/scan of a project. Either on the cli -Dsonar.webhooks.project=https://my-jenkins-domain.tld/sonarqube-webhook/ or in sonar-project.properties onar.webhooks.project=https://my-jenkins-domain.tld/sonarqube-webhook/

这篇关于在Jenkinsfile中设置SonarQube Webhook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆