Template for a good new topic, formatted with Markdown:
ALM used: GitHub
CI system used: Jenkins
Languages of the repository: Java / Kotlin
Error observed
Last week we activated a new set of conditions for our repository so it’s included in our Quality Gate. Among the new conditions, we activated a hardcoded limit of new lines added. It works flawlessly on PRs, but when sonar runs on our main branch, it reports an error as there are thousands of lines added.
I do understand this number comes from the last “30 days of code added” in that branch. I was wondering if it makes sense at all to run these checks on long live branches at all. I’d like to know what would be the best way to restrict this “lines added” condition to run only on PRs, or to set different behaviours per branch.
I’m afraid it’s not possible to have different behavior per branch. The On New Code metrics are designed to apply to all branches and to pull requests, as the message says when you configure the quality gate:
Conditions on New Code
Conditions on New Code apply to all branches and to Pull Requests.
As such, I cannot think of good workaround for the New Lines metric, because the same value will not make sense for pull requests and for their target branch at the same time.
Another thing you could try is to reduce the number of days for your new code definition. Maybe you can find a good value that will work with the new lines condition you have set up.You can find the option in the Administration settings of your project --> General settings --> General --> New code.
Thanks a lot Martin and Janos. Indeed, that value won’t make sense for both Prs and long lived branches. I’ll try to play around with the number of days, see if I can find a value that fits all. Thanks!