I am using some manual metrics on my SonarQube Project. I want to use my own manual metrics as a condition on a Quality Gate. I searched through documentation and internet. I could not find anything about the topic. The SonarQube allows to use only system metrics. Are there any way to use Manual Metrics on a condition in QualityGate ?
Quality Gate conditions can actually be created based on manual metrics, but some metric types are not available: DATA, RATING and (obviously) Quality Gate status.
Manual metrics are created with the hidden attribute set to NULL in the database. Changing it to 0 makes the manual metric appear in the "Add Condition" dropdown of the quality gates.
Since the manual metrics seem to work fine with the quality gates, I assume this is a bug in SonarQube.
Credit to Stefan Egli's comment which guided me in the right direction.
Related
I'm kinda new to SonarQube and I just found this:
Question: How? Shouldn't the Quality Gate be failing? Or do the quality gate only work for new code?
The quality rules are the default ones
Yes, it is possible. Why? It depends how the Quality Gate is configured.
Copied from SonarQube Quality Gates documentation:
Each Quality Gate condition is a combination of:
measure
comparison operator
error value
For instance, a condition might be:
measure: Blocker issue
comparison operator: >
error value: 0
Which can be stated as: No blocker issues.
Your Quality Gate could be configured to check only new code or even to not check the code at all.
Sonar way (Built-in) Quality Profile on SonarQube 7.9.2 checks only new code:
I recently used sonarqube api to create a dynamic quality gate, it increases or decreases the acceptable number for the project, according to the number of lines of code, but I'm having some problems ...
It works like this, after the analysis I use the number of lines and calculate the quality gate to increase or lower the acceptable limit
I use the sonar line count itself to avoid mismatching information, but whenever I update a quality gate, the project status is not updated.
For example, if a project was with the quality gate with the status "Passed", after I update the quality gate, it should change the status to "Failed", but it remains "Passed" because I did not perform a new analysis.
How can I request pro sonar to re-execute the project status according to the quality gate change?
I'm using sonarqube 6.0
Thanks
You have no choice but to re-run an analysis if you want your quality gate to be updated.
Just as a side note: it looks like you are trying to hack SonarQube features, I would not recommend to go into that way because you will for sure face problems. Instead, I highly encourage you to read "Water Leak Changes the Game for Technical Debt Management" and consider using the built-in quality gate that puts the focus on new code: this is the best and easiest way to improve code quality over-time with almost no effort and no friction.
I'm using SonarQube 5.4 and I noticed that when a metric, which is used to calculate the Quality Gate status, is missing then that is handled in the same way as if the criteria was met.
Isn't it more intuitive that the Quality Gate fails if there is missing information to determine the status?
Or at least that it is configurable to fail by default if there is missing data?
Instead of having the quality gate able to deal with a missing code coverage measure our goal is to find a standard way to force coverage to 0 when there is no coverage information available for one source file. This is not an easy subject but this is something that we'll try to fix part of https://jira.sonarsource.com/browse/MMF-345.
Is there a way to overwrite the quality gate status of a Sonarqube (5.6) project?
Use case is that we check for technical dept on new code to not be higher than 5%. In case there are additional rules activated in the quality profile, next time a project was checked it will violate the quality gate, even though the technical dept was not introduced by new code but with new rules instead.
Currently there is no way to overwrite quality gate status. From this thread on Google Groups by G. Ann Campbell:
There's not. The best approach is a strategy one: only update the profile / add rules when a new version is just beginning.
Of course, that doesn't really address the issue that new rules raise "new" issues on old code. For that I don't have an answer.
I have a case in which I want a plugin to save metrics on SCM Tickets.
At the moment I defined a custom SCMTicket resource (extending the Resource class) and added some metrics using the getMetrics method in a class implementing the Metrics interface.
I created a Sensor that just adds a dummy measurement on one of my metrics. My resources are not saved before saving the measurement as the saveMeasure method should do that automatically.
The problem I have is that my resources are not saved and the measures are also not saved. The metrics are saved.
Am I using a totally wrong approach or do I have to do something more to save this?
Thanks in advance!
From a conceptual standpoint, this is a wrong approach.
The SonarQube Platform is intended to measure and track code quality. I can see an argument that tickets reflect quality, but they are not themselves code and do not have quality (or a lack thereof).
Edit
For aggregate values, such as the average ticket duration you mention in your comment, the best place to record them is on the project. (Which makes sense not just from an API perspective, but from a metric ownership perspective if you think about it.)
Note that once upon a time, SonarSource actually offered a JIRA plugin, but abandoned it after deciding that JIRA metrics weren't really about code quality.