sonar.Qualitygate is Deprecated in Sonar Qube 5.3. What is the alternative?

后端 未结 3 814
日久生厌
日久生厌 2021-01-19 04:09

Context: In Sonar Qube, there exists a custom Quality Gate which is called say abcd. This is NOT the default quality gate. And in Jenkins, I had configured this

3条回答
  •  灰色年华
    2021-01-19 04:43

    You can still dynamically create an association gate - project via Sonarqube Web API.

    From your Sonarqube instance, go to its /web_api URL (e.g. http://my-sonarqube/web_api) and check the list of available operations.

    The web_api/api/qualitygates is the set of operations related to quality gates. The web_api/api/qualitygates/select is the operation you need to associate a gate to a project.

    Hence, as replacement of the deprecated sonar.qualitygate, you can use either the manual association via the web UI or a dynamic (and automated) association via web API, recommended. The latter case is the way to go in case of Continous Integration jobs (as you mentioned Jenkins in this context) that would need to create dynamically the link (especially useful for branches management).

    As a mandatory step for this operation to work, you need to pass some permissions, e.g. an user token, as recommended approach from official Sonarqube documentation on Web API.

    An example of what a CI step may look like just before invoking the sonar:sonar step:

    curl -u ${sonar.password.token}: ${sonar.setqualitygate.url} \
    -d "gateId=${sonar.gate.id}&projectKey=${sonar.project.key}:${planRepository.branch}"
    

    Where:

    • sonar.password.token is a token you need to generate from the Sonarqube User management page, for a technical user (e.g. a Jenkins user used to make the connection between the component)
    • sonar.setqualitygate.url the URL of the REST API endpoint (e.g. http://your.sonarqube.domain/api/qualitygates/select)
    • sonar.gate.id is the gate id, you can find it easily on the URL of the concerned gate (e.g. http://your.sonarqube.domain/quality_gates/show/)
    • sonar.project.key and planRepository.branch here we are building dynamically the name of the project for a certain branch as well, you can skip this step if you don't want to handle branches dynamically (e.g. easy to do in Bamboo, a bit more tricky in Jenkins)

提交回复
热议问题