Hi,
I have a branch name “env/v2/dev-test”, and I want it to be included in Long lived branches on sonar.
The regex I am using is /(^env.*)-*/ and it matches my branch on this website: https://regex101.com/.
There are 4 branches that match this regex in my repository. But I still cannot see my branches with name “env/…” in the branches tab.
Techstack:
Bitbucket
Java Spring Boot
Java 17
Sonar 4.4.1.3373
Additional questions:
Do I have run the pipeline every time after updating the regex?
Does my pipeline script need to updated in all the branches? BTW it scanned master without any update in the pipeline, so I assumed I dont need to include pipeline code in every branch.
Your best bet here is to upgrade. Not being sure where you’re starting from, I can only guess at your upgrade path, but you must hit every LTA release between where you are and the current version. E.G.
Thanks for that update. I’ve recategorized your thread to SonarCloud.
Since you are on SonarCloud, there’s no need to upgrade.
You’ll want to edit your long-lived branch pattern to a regex that matches your branch name. You say you tested your regex against regex101.com, but it seems that that site expects you to use regex delimiters: leading and trailing forward slashes. SonarCloud doesn’t need any delimiters; the whole input is the regex. So as a first step, I would trim off those slashes. That gets us to
(^env.*)-*
What that describes is a string that starts with env followed by any number of any character (.*), followed by any number of dashes (-*). And that doesn’t match the branch name string you’re using. To match that branch name, something like this would work:
env/.*
However, that would exclude branches without that prefix.
No. It’s worth being very explicit here that a branch’s type is set on its first analysis and is then immutable. So you could theoretically set a pattern that exactly matches your branch name, analyze that branch, and then reset the pattern. Your already-analyzed branch will be unaffected at its next analysis.
Note also, that to get your env* branch set up as a long-lived branch, you’ll need to first delete it from SonarCloud if it currently exists there, and re-create it.
I narrowed down the regex to (^env/v2/.)-
This only deals with branches that look like env/v2/dev*.
The branch I am trying to analyse is env/v2/dev-aws-pipe.
Below is a screenshot of how I added it into my sonar cloud.
But it is only putting it in short lived branch.
BTW I have also tried the exact string, it does not work either
Hiya, Actualy the regex was working but my due to cache the project updated were not being scanned. I removed cache and it works fine now, a little slow but that is fine as I don’t runt he pipeline daily.