# Long living branches pattern does not work anymore

**URL:** <https://community.sonarsource.com/t/long-living-branches-pattern-does-not-work-anymore/761>\
**Category:** SonarQube Cloud\
**Tags:** azuredevops-services\
**Created:** [July 5, 2018, 9:13am UTC](https://community.sonarsource.com/t/long-living-branches-pattern-does-not-work-anymore/761 "2018-07-05T09:13:39Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![TobiasH](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@TobiasH](https://community.sonarsource.com/u/TobiasH)\
**Post date:** [July 5, 2018, 9:13am UTC](https://community.sonarsource.com/t/long-living-branches-pattern-does-not-work-anymore/761/1 "2018-07-05T09:13:39Z")

</div>

Hello,

for some reason all analysis of our release branches now appear as short lived branchs of the main branch. Checking the background tasks it seems to stopped working after June, 28.

We use VSTS with the SonarCloud build task. Our git branches are named `main`, `develop`, `release/1805`, `release/1807`, etc. The long living branches pattern is defined as `(master|develop|release\/).*` and hasn’t changed recently.

The log from our latest build on branch `release/1805` contains this entry:  
`2018-07-05T08:37:31.6320360Z INFO: Branch name: 1805, type: short living`

In a previous build the log contained this entry:  
`2018-06-28T18:55:24.8292473Z INFO: Branch name: release/1805, type: long living`

Please let me know if you need more information.

Regards,  
Tobias

---

<div class="post-metadata">

**Author:** ![Fabrice\_Bellingard](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/fabrice_bellingard/32/39_2.png) [@Fabrice\_Bellingard](https://community.sonarsource.com/u/Fabrice_Bellingard)\
**Post date:** [July 6, 2018, 3:06pm UTC](https://community.sonarsource.com/t/long-living-branches-pattern-does-not-work-anymore/761/2 "2018-07-06T15:06:19Z")

</div>

Hi Tobias

I just checked and it worked correctly, given the exact same pattern as you:

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/1X/e2f156f56ec86636737c330b4679338f12218688.png)

You might be missing one important point: once a branch is created, it remains short-lived or long-lived for its whole time life. This pattern is used only when creating a branch for the first time.

---

<div class="post-metadata">

**Author:** ![TobiasH](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@TobiasH](https://community.sonarsource.com/u/TobiasH)\
**Post date:** [July 6, 2018, 4:39pm UTC](https://community.sonarsource.com/t/long-living-branches-pattern-does-not-work-anymore/761/3 "2018-07-06T16:39:40Z")

</div>

Hello Fabrice,

the strange thing is release/1801, release/1803 and release/1805 already exist as long living branches, but updates stopped after last friday. In addition to that I now have branches 1801, 1803, 1805 and 1807 as short living branches under the main branch.

Our git branch release/1807 was created earlier this week and analysis is performed with the same build definition we use for all the other release branches. It was created as a short living branch in SonarCloud right from the start.

I deleted all those short living branches for now and check if they get recreated.

---

<div class="post-metadata">

**Author:** ![TobiasH](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@TobiasH](https://community.sonarsource.com/u/TobiasH)\
**Post date:** [July 7, 2018, 9:50am UTC](https://community.sonarsource.com/t/long-living-branches-pattern-does-not-work-anymore/761/4 "2018-07-07T09:50:46Z")

</div>

After I removed the short living branches, our git branch `release/1805` was created as short living branch `1805` again last night. Although `release/1805` already exists as a long living branch in SonarCloud and the pattern should have matched.

The same applies to the git branch `release/1807`, except that I haven’t been able to create a long living branch in SonarCloud yet.

Something’s definitely not right. Any ideas on what I can check or change next?

**EDIT** : I found something in our log files which might be related to the problem I am facing. The VSTS build tasks for SonarCloud got updated recently.

Last working analysis:

- Prepare Analysis Configuration v1.3.0
- Run Code Analysis v1.3.0

First ‘failing’ analysis:

- Prepare Analysis Configuration v1.3.1
- Run Code Analysis v1.3.0

Regards,  
Tobias

---

<div class="post-metadata">

**Author:** ![TobiasH](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@TobiasH](https://community.sonarsource.com/u/TobiasH)\
**Post date:** [July 9, 2018, 6:34pm UTC](https://community.sonarsource.com/t/long-living-branches-pattern-does-not-work-anymore/761/6 "2018-07-09T18:34:12Z")

</div>

I’m still unable to get SonarCloud to recognize our release branches correctly. I triggered another build from VSTS for the _release/1805_ branch, this time with `system.debug = true` to get some additional debug information.

This piece from the _Prepare Analysis Configuration_ step looks interesting.

```auto
##[debug]Build.Repository.Provider=TfsGit
##[debug]Build.SourceBranch=refs/heads/release/1805
##[debug]Default branch of this repository is 'refs/heads/master'
##[debug]Build.SourceBranchName=1805

```

Having a look at the last commits on the sonar-scanner-vsts repo I found this:

```auto
let isDefaultBranch = true;

if (provider === 'TfsGit') {
    isDefaultBranch = currentBranch === (await getDefaultBranch(collectionUrl));
}

if (!isDefaultBranch) {
    props['sonar.branch.name'] = tl.getVariable('Build.SourceBranchName');
}

```

Source: [https://github.com/SonarSource/sonar-scanner-vsts/commit/7106f4914fe2c5aeaa03db38c6e882a1b1c3177a](https://github.com/SonarSource/sonar-scanner-vsts/commit/7106f4914fe2c5aeaa03db38c6e882a1b1c3177a)

Please correct me if I’m wrong but your previous version used `Build.SourceBranch` and truncated the `refs/heads/` part to get the source branch name instead of simply using `Build.SourceBranchName` which only keeps the last component of the ‘path’.

Regards,  
Tobias

---

<div class="post-metadata">

**Author:** ![Julien\_HENRY](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/julien_henry/32/61_2.png) [@Julien\_HENRY](https://community.sonarsource.com/u/Julien_HENRY)\
**Post date:** [July 10, 2018, 6:59am UTC](https://community.sonarsource.com/t/long-living-branches-pattern-does-not-work-anymore/761/7 "2018-07-10T06:59:10Z")

</div>

Hi Tobias,

You’re right, I changed the implementation in the latest release, to rely on the Build.SourceBranchName variable, which seems to me less fragile than manually assuming I should truncate the ‘refs/heads’ prefix.

The fact if contains only the last string after last ‘/’ looks like a bug to me.

I will check with Microsoft if this is a known bug on VSTS side.

---

<div class="post-metadata">

**Author:** ![TobiasH](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@TobiasH](https://community.sonarsource.com/u/TobiasH)\
**Post date:** [July 10, 2018, 7:05am UTC](https://community.sonarsource.com/t/long-living-branches-pattern-does-not-work-anymore/761/8 "2018-07-10T07:05:22Z")

</div>

Hi Julien,

it’s not a bug: [https://docs.microsoft.com/en-us/vsts/pipelines/build/variables?view=vsts&tabs=batch#buildsourcebranchname](https://docs.microsoft.com/en-us/vsts/pipelines/build/variables?view=vsts&tabs=batch#buildsourcebranchname)

I had some trouble with that variable before when I used it in one of my build definitions and it behaved differently from what I expected.

Regards,  
Tobias

---

<div class="post-metadata">

**Author:** ![Julien\_HENRY](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/julien_henry/32/61_2.png) [@Julien\_HENRY](https://community.sonarsource.com/u/Julien_HENRY)\
**Post date:** [July 10, 2018, 8:34am UTC](https://community.sonarsource.com/t/long-living-branches-pattern-does-not-work-anymore/761/9 "2018-07-10T08:34:18Z")

</div>

OK, waiting for Microsoft opinion on this, we will revert to the previous state:  
[https://jira.sonarsource.com/browse/VSTS-165](https://jira.sonarsource.com/browse/VSTS-165)

Thanks for reporting this.

---

<div class="post-metadata">

**Author:** ![TobiasH](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@TobiasH](https://community.sonarsource.com/u/TobiasH)\
**Post date:** [July 11, 2018, 8:46am UTC](https://community.sonarsource.com/t/long-living-branches-pattern-does-not-work-anymore/761/10 "2018-07-11T08:46:07Z")

</div>

Great,

do you have an ETA when the fixed version will be available in the Visual Studio Marketplace?

Regards,  
Tobias

---

<div class="post-metadata">

**Author:** ![Julien\_HENRY](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/julien_henry/32/61_2.png) [@Julien\_HENRY](https://community.sonarsource.com/u/Julien_HENRY)\
**Post date:** [July 11, 2018, 12:26pm UTC](https://community.sonarsource.com/t/long-living-branches-pattern-does-not-work-anymore/761/11 "2018-07-11T12:26:26Z")

</div>

I just deployed version 1.3.2 of the prepare task. Please confirm that it solves your problem.

---

<div class="post-metadata">

**Author:** ![TobiasH](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@TobiasH](https://community.sonarsource.com/u/TobiasH)\
**Post date:** [July 11, 2018, 2:18pm UTC](https://community.sonarsource.com/t/long-living-branches-pattern-does-not-work-anymore/761/12 "2018-07-11T14:18:24Z")

</div>

Looks good!

The missing release branch was finally created and the existing release branches were updated again.

Thanks,  
Tobias

---

<div class="post-metadata">

**Author:** ![Julien\_HENRY](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/julien_henry/32/61_2.png) [@Julien\_HENRY](https://community.sonarsource.com/u/Julien_HENRY)\
**Post date:** [July 12, 2018, 7:24am UTC](https://community.sonarsource.com/t/long-living-branches-pattern-does-not-work-anymore/761/13 "2018-07-12T07:24:45Z")

</div>

Thanks Tobias for the confirmation.
