Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot generate version number on BitBucket Cloud Pipelines #3057

Closed
davidkeaveny opened this issue Mar 21, 2022 · 11 comments · Fixed by #3069
Closed

Cannot generate version number on BitBucket Cloud Pipelines #3057

davidkeaveny opened this issue Mar 21, 2022 · 11 comments · Fixed by #3069
Labels
Milestone

Comments

@davidkeaveny
Copy link
Contributor

I am using Atlassian's BitBucket Cloud edition and their Pipelines CI service to build a new application (so we haven't done our first merge back to master yet). When I run GitVersion to calculate the version number, the pipeline step fails with the message Gitversion could not determine which branch to treat as the development branch (default is 'develop') nor release-able branch (default is 'main' or 'master'), either locally or remotely. Ensure the local clone and checkout match the requirements or considering using 'GitVersion Dynamic Repositories'.

Expected Behavior

The pipeline step should generate the calculated version number.

Actual Behavior

The pipeline step is erroring with the following exception:

System.InvalidOperationException: Gitversion could not determine which branch to treat as the development branch (default is 'develop') nor release-able branch (default is 'main' or 'master'), either locally or remotely. Ensure the local clone and checkout match the requirements or considering using 'GitVersion Dynamic Repositories'
   at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(Int32 recursions, IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 150
   at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfigurationInternal(Int32 recursions, IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 54
   at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfiguration(IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 28
   at GitVersion.GitVersionContextFactory.Create(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionContextFactory.cs:line 38
   at GitVersion.GitVersionCoreModule.<>c__DisplayClass0_0.<RegisterTypes>b__1() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\GitVersionCoreModule.cs:line 37
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at GitVersion.VersionCalculation.NextVersionCalculator.get_context() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 15
   at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 30
   at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionCalculateTool.cs:line 52
   at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.App\GitVersionExecutor.cs:line 66

Steps to Reproduce

I am using the following configuration for Pipelines:

image: mcr.microsoft.com/dotnet/sdk:6.0

definitions:
  services:
    docker:
      memory: 2048  # Increasing memory available to stop service memory limit errors

pipelines:
  default:
  - step:
      name: Version
      script:
        - export PATH="$PATH:/root/.dotnet/tools"
        - dotnet tool install --global GitVersion.Tool --version 5.*
        - dotnet-gitversion /diag /output buildserver
  - step:
      name: Build and test
      script:
        - dotnet build --configuration Release

If I run dotnet-gitversion locally on the repo, then the version number is calculated as expected, so I believe that my GitVersion.yml is good.

The complete output from the build server is as follows:

+ export PATH="$PATH:/root/.dotnet/tools"

+ dotnet tool install --global GitVersion.Tool --version 5.*
You can invoke the tool using the following command: dotnet-gitversion
Tool 'gitversion.tool' (version '5.9.0') was successfully installed.

+ dotnet-gitversion /diag /output buildserver
INFO [03/21/22 19:55:55:65] Applicable build agent found: 'LocalBuild'.
INFO [03/21/22 19:55:55:70] Working directory: /opt/atlassian/pipelines/agent/build
INFO [03/21/22 19:55:55:72] Branch from build environment: 
INFO [03/21/22 19:55:55:72] Project root is: /opt/atlassian/pipelines/agent/build/
INFO [03/21/22 19:55:55:72] DotGit directory is: /opt/atlassian/pipelines/agent/build/.git
INFO [03/21/22 19:55:55:76] Begin: Loading version variables from disk cache
  INFO [03/21/22 19:55:55:76] Cache file /opt/atlassian/pipelines/agent/build/.git/gitversion_cache/38B046B52AC5EC4E4198D3DD851D7CAB78F4B954.yml not found.
  INFO [03/21/22 19:55:55:76] End: Loading version variables from disk cache (Took: 0.84ms)
  INFO [03/21/22 19:55:55:76] Using latest commit on specified branch
  INFO [03/21/22 19:55:55:89] Begin: Attempting to inherit branch configuration from parent branch
    INFO [03/21/22 19:55:55:90] Begin: Finding branch source of 'feature/try-versioning-again'
    INFO [03/21/22 19:55:55:91] End: Finding branch source of 'feature/try-versioning-again' (Took: 7.88ms)
    INFO [03/21/22 19:55:55:91] Begin: Getting branches containing the commit '3a2daf7'.
      INFO [03/21/22 19:55:55:91] Trying to find direct branches.
      INFO [03/21/22 19:55:55:91] No direct branches found, searching through all branches.
    INFO [03/21/22 19:55:55:91] End: Getting branches containing the commit '3a2daf7'. (Took: 0.09ms)
    INFO [03/21/22 19:55:55:91] Found possible parent branches: 
  INFO [03/21/22 19:55:55:91] End: Attempting to inherit branch configuration from parent branch (Took: 24.88ms)
  ERROR [03/21/22 19:55:55:93] An unexpected error occurred:
System.InvalidOperationException: Gitversion could not determine which branch to treat as the development branch (default is 'develop') nor release-able branch (default is 'main' or 'master'), either locally or remotely. Ensure the local clone and checkout match the requirements or considering using 'GitVersion Dynamic Repositories'
   at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(Int32 recursions, IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 150
   at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfigurationInternal(Int32 recursions, IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 54
   at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfiguration(IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 28
   at GitVersion.GitVersionContextFactory.Create(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionContextFactory.cs:line 38
   at GitVersion.GitVersionCoreModule.<>c__DisplayClass0_0.<RegisterTypes>b__1() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\GitVersionCoreModule.cs:line 37
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at GitVersion.VersionCalculation.NextVersionCalculator.get_context() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 15
   at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 30
   at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionCalculateTool.cs:line 52
   at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.App\GitVersionExecutor.cs:line 66
  INFO [03/21/22 19:55:55:93] Attempting to show the current git graph (please include in issue): 
  INFO [03/21/22 19:55:55:93] Showing max of 100 commits
  INFO [03/21/22 19:55:55:96] * 3a2daf7 58 seconds ago  (HEAD -> feature/try-versioning-again, origin/feature/try-versioning-again)
* 7ccf30a 14 hours ago 
* 324d3bb 5 days ago 
* 57196bb 7 days ago 
* 0987380 7 days ago 
* a94c81b 7 days ago 
* b78bfae 11 days ago 
* 9adf39c 11 days ago 
* 939fe35 11 days ago 
* eb3d0db 12 days ago 
* 9e69f37 13 days ago 
* 9ebb0ad 13 days ago 
* 40a2e7c 2 weeks ago 
* dc5eb90 3 weeks ago 
* dbdcae4 3 weeks ago 
* 184a21f 3 weeks ago 
* e4558a2 3 weeks ago 
* 7c7d419 3 weeks ago 
* 504c718 3 weeks ago 
* 607b410 3 weeks ago 
* fcdc4d8 3 weeks ago 
* 390b63d 4 weeks ago 
* 3be6b4d 4 weeks ago 
* 6333b2f 4 weeks ago 
* 71a95c4 4 weeks ago 
* d61ae77 4 weeks ago 
* 888a3a3 5 weeks ago 
* c5cbd88 5 weeks ago 
* 32f75fd 5 weeks ago 
* 9c3294c 5 weeks ago 
* e63d68b 5 weeks ago 
* 145605c 5 weeks ago 
* 4a65de7 5 weeks ago 
* ae79c25 6 weeks ago 
* f4a2995 6 weeks ago 
* 5868ad6 6 weeks ago 
* 548c0e2 6 weeks ago 
* ea26a89 6 weeks ago 
* 606e09a 6 weeks ago 
* 0ee0257 7 weeks ago 
* d1e0687 7 weeks ago 
* 53a7012 8 weeks ago 
* 431d90d 8 weeks ago 
* 542a056 8 weeks ago 
* 731572b 8 weeks ago 
* bee2789 8 weeks ago 
* bfe3346 8 weeks ago 
* 8d86a44 9 weeks ago 
* 5239b72 9 weeks ago 
* 5a724db 9 weeks ago  (grafted)
@asbjornu
Copy link
Member

Perhaps a duplicate of #2900?

@davidkeaveny
Copy link
Contributor Author

I don't believe so - the issue you linked to says that the error they experience occurs on develop but that it works okay when they build on a feature branch. Also, I don't get the error about working on a detached HEAD. I did try a few of the suggested options - calling git fetch --unshallow, which at least added a commit graph to the output, and setting the environment variable Git_Branch (or should it be GIT_BRANCH? The linked issue gives both examples).

With those changes, my Pipelines build step looks like this:

pipelines:
  default:
  - step:
      name: Version
      script:
        - export PATH="$PATH:/root/.dotnet/tools"
        - export Git_Branch=$BITBUCKET_BRANCH
        - export GIT_BRANCH=$BITBUCKET_BRANCH
        - git fetch --unshallow
        - dotnet tool install --global GitVersion.Tool --version 5.*
        - dotnet-gitversion /diag /output buildserver

and the output that it produces is:

INFO [03/29/22 0:52:45:93] Applicable build agent found: 'LocalBuild'.
INFO [03/29/22 0:52:45:97] Working directory: /opt/atlassian/pipelines/agent/build
INFO [03/29/22 0:52:45:98] Branch from build environment: 
INFO [03/29/22 0:52:45:98] Project root is: /opt/atlassian/pipelines/agent/build/
INFO [03/29/22 0:52:45:98] DotGit directory is: /opt/atlassian/pipelines/agent/build/.git
INFO [03/29/22 0:52:46:01] Begin: Loading version variables from disk cache
  INFO [03/29/22 0:52:46:01] Cache file /opt/atlassian/pipelines/agent/build/.git/gitversion_cache/1418D04B15CD7B40F9CB92614178684F5D0D2D04.yml not found.
  INFO [03/29/22 0:52:46:01] End: Loading version variables from disk cache (Took: 0.65ms)
  INFO [03/29/22 0:52:46:02] Using latest commit on specified branch
  INFO [03/29/22 0:52:46:12] Begin: Attempting to inherit branch configuration from parent branch
    INFO [03/29/22 0:52:46:13] Begin: Finding branch source of 'feature/try-versioning-again'
    INFO [03/29/22 0:52:46:13] End: Finding branch source of 'feature/try-versioning-again' (Took: 6.00ms)
    INFO [03/29/22 0:52:46:13] Begin: Getting branches containing the commit 'ee3bfb2'.
      INFO [03/29/22 0:52:46:13] Trying to find direct branches.
      INFO [03/29/22 0:52:46:13] No direct branches found, searching through all branches.
    INFO [03/29/22 0:52:46:13] End: Getting branches containing the commit 'ee3bfb2'. (Took: 0.08ms)
    INFO [03/29/22 0:52:46:14] Found possible parent branches: 
  INFO [03/29/22 0:52:46:14] End: Attempting to inherit branch configuration from parent branch (Took: 19.06ms)
  ERROR [03/29/22 0:52:46:15] An unexpected error occurred:
System.InvalidOperationException: Gitversion could not determine which branch to treat as the development branch (default is 'develop') nor release-able branch (default is 'main' or 'master'), either locally or remotely. Ensure the local clone and checkout match the requirements or considering using 'GitVersion Dynamic Repositories'
   at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(Int32 recursions, IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 150
   at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfigurationInternal(Int32 recursions, IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 54
   at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfiguration(IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 28
   at GitVersion.GitVersionContextFactory.Create(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionContextFactory.cs:line 38
   at GitVersion.GitVersionCoreModule.<>c__DisplayClass0_0.<RegisterTypes>b__1() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\GitVersionCoreModule.cs:line 37
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at GitVersion.VersionCalculation.NextVersionCalculator.get_context() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 15
   at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 30
   at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionCalculateTool.cs:line 52
   at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.App\GitVersionExecutor.cs:line 66
  INFO [03/29/22 0:52:46:15] Attempting to show the current git graph (please include in issue): 
  INFO [03/29/22 0:52:46:15] Showing max of 100 commits
  INFO [03/29/22 0:52:46:18] * ee3bfb2 49 seconds ago  (HEAD -> feature/try-versioning-again, origin/feature/try-versioning-again)
* ef21d18 5 minutes ago 
* d5430fc 10 minutes ago 
* 79c90bf 14 minutes ago 
* b365d3f 17 minutes ago 
* 3a2daf7 7 days ago 
* 7ccf30a 8 days ago 
* 324d3bb 12 days ago 
* 57196bb 2 weeks ago 
* 0987380 2 weeks ago 
* a94c81b 2 weeks ago 
* b78bfae 3 weeks ago 
* 9adf39c 3 weeks ago 
* 939fe35 3 weeks ago 
* eb3d0db 3 weeks ago 
* 9e69f37 3 weeks ago 
* 9ebb0ad 3 weeks ago 
* 40a2e7c 3 weeks ago 
* dc5eb90 4 weeks ago 
* dbdcae4 4 weeks ago 
* 184a21f 4 weeks ago 
* e4558a2 4 weeks ago 
* 7c7d419 4 weeks ago 
* 504c718 4 weeks ago 
* 607b410 4 weeks ago 
* fcdc4d8 4 weeks ago 
* 390b63d 5 weeks ago 
* 3be6b4d 5 weeks ago 
* 6333b2f 5 weeks ago 
* 71a95c4 5 weeks ago 
* d61ae77 5 weeks ago 
* 888a3a3 6 weeks ago 
* c5cbd88 6 weeks ago 
* 32f75fd 6 weeks ago 
* 9c3294c 6 weeks ago 
* e63d68b 6 weeks ago 
* 145605c 6 weeks ago 
* 4a65de7 6 weeks ago 
* ae79c25 7 weeks ago 
* f4a2995 7 weeks ago 
* 5868ad6 7 weeks ago 
* 548c0e2 7 weeks ago 
* ea26a89 7 weeks ago 
* 606e09a 7 weeks ago 
* 0ee0257 8 weeks ago 
* d1e0687 8 weeks ago 
* 53a7012 9 weeks ago 
* 431d90d 9 weeks ago 
* 542a056 9 weeks ago 
* 731572b 9 weeks ago 
* bee2789 10 weeks ago 
* bfe3346 10 weeks ago 
* 8d86a44 10 weeks ago 
* 5239b72 10 weeks ago 
* 5a724db 2 months ago 
* 65cce82 2 months ago 
* e1c48bd 3 months ago 
* 426f3ec 3 months ago 
* 819edbc 4 months ago 
* 36f5e5d 4 months ago 
* 2d36c50 4 months ago 
* 559c758 4 months ago 
* 846234f 4 months ago 
* e37576e 4 months ago 
* b748123 4 months ago 
* aff579d 4 months ago 
* f31c2de 4 months ago 
*   680d2f8 1 year, 1 month ago 
|\  
| * 35c4397 1 year, 1 month ago 
| * 149021d 1 year, 1 month ago 
| * ceb628f 1 year, 2 months ago 
| *   b9fe8d3 1 year, 2 months ago 
| |\  
| | *   bfb3666 1 year, 2 months ago 
| | |\  
| | * | 5cefc65 1 year, 2 months ago 
| | * | 3424fb9 1 year, 4 months ago 
| * | | c2c1aa1 1 year, 2 months ago 
| | |/  
| |/|   
| * | 11beec6 1 year, 2 months ago 
| * | 9f65d8e 1 year, 3 months ago 
| * | 980bb26 1 year, 3 months ago 
| * | 54ac1a3 1 year, 3 months ago 
| * | 8663818 1 year, 4 months ago 
| * | be1fc3b 1 year, 4 months ago 
| * | d05ac96 1 year, 4 months ago 
| * | 58a4823 1 year, 4 months ago 
| |/  
| * 950ae95 1 year, 4 months ago 
| * 0ccb107 1 year, 4 months ago 
| * d05d8d2 1 year, 4 months ago 
| * 25673b6 1 year, 5 months ago 
| * ca54ef8 1 year, 5 months ago 
| * 69a2ec2 1 year, 5 months ago 
| * 30639a3 1 year, 5 months ago 
| *   e4baa71 1 year, 5 months ago 
| |\  
| | * 9eaeb96 1 year, 5 months ago 
| * | 62c4a2d 1 year, 5 months ago 
| |/  
| * cf5f6f2 1 year, 5 months ago 
| * fbb6c8b 1 year, 5 months ago 
| * 653a5d0 1 year, 5 months ago 
| * 7d6e02c 1 year, 6 months ago 
| * bcbd0bd 1 year, 6 months ago 
| *   60776af 1 year, 6 months ago 
| |\  

@davidkeaveny
Copy link
Contributor Author

davidkeaveny commented Mar 30, 2022

I've queried on the Atlassian community boards, and their suggestion was to do a full clone of the repo, and that does change the output a little (I've snipped off the commit graph for now):

INFO [03/30/22 6:44:40:99] Applicable build agent found: 'LocalBuild'.
INFO [03/30/22 6:44:41:03] Working directory: /opt/atlassian/pipelines/agent/build
INFO [03/30/22 6:44:41:05] Branch from build environment: 
INFO [03/30/22 6:44:41:05] Project root is: /opt/atlassian/pipelines/agent/build/
INFO [03/30/22 6:44:41:05] DotGit directory is: /opt/atlassian/pipelines/agent/build/.git
INFO [03/30/22 6:44:41:08] Begin: Loading version variables from disk cache
  INFO [03/30/22 6:44:41:08] Cache file /opt/atlassian/pipelines/agent/build/.git/gitversion_cache/433959C65FE5AE7113119964172265A2BAE898C8.yml not found.
  INFO [03/30/22 6:44:41:08] End: Loading version variables from disk cache (Took: 0.68ms)
  INFO [03/30/22 6:44:41:08] Using latest commit on specified branch
  INFO [03/30/22 6:44:41:21] Begin: Attempting to inherit branch configuration from parent branch
    INFO [03/30/22 6:44:41:22] Begin: Finding branch source of 'feature/try-versioning-again'
    INFO [03/30/22 6:44:41:23] End: Finding branch source of 'feature/try-versioning-again' (Took: 10.11ms)
    INFO [03/30/22 6:44:41:23] Begin: Getting branches containing the commit '4aec084'.
      INFO [03/30/22 6:44:41:23] Trying to find direct branches.
      INFO [03/30/22 6:44:41:23] No direct branches found, searching through all branches.
      INFO [03/30/22 6:44:41:23] Searching for commits reachable from 'origin/develop'.
      INFO [03/30/22 6:44:41:24] The branch 'origin/develop' has no matching commits.
      INFO [03/30/22 6:44:41:24] Searching for commits reachable from 'origin/master'.
      INFO [03/30/22 6:44:41:24] The branch 'origin/master' has no matching commits.
    INFO [03/30/22 6:44:41:24] End: Getting branches containing the commit '4aec084'. (Took: 10.37ms)
    INFO [03/30/22 6:44:41:24] Found possible parent branches: 
  INFO [03/30/22 6:44:41:24] End: Attempting to inherit branch configuration from parent branch (Took: 37.12ms)
  ERROR [03/30/22 6:44:41:26] An unexpected error occurred:
System.InvalidOperationException: Gitversion could not determine which branch to treat as the development branch (default is 'develop') nor release-able branch (default is 'main' or 'master'), either locally or remotely. Ensure the local clone and checkout match the requirements or considering using 'GitVersion Dynamic Repositories'
   at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(Int32 recursions, IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 150
   at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfigurationInternal(Int32 recursions, IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 54
   at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfiguration(IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 28
   at GitVersion.GitVersionContextFactory.Create(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionContextFactory.cs:line 38
   at GitVersion.GitVersionCoreModule.<>c__DisplayClass0_0.<RegisterTypes>b__1() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\GitVersionCoreModule.cs:line 37
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at GitVersion.VersionCalculation.NextVersionCalculator.get_context() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 15
   at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 30
   at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionCalculateTool.cs:line 52
   at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.App\GitVersionExecutor.cs:line 66

Of which, the following 4 lines are new:

      INFO [03/30/22 6:44:41:23] Searching for commits reachable from 'origin/develop'.
      INFO [03/30/22 6:44:41:24] The branch 'origin/develop' has no matching commits.
      INFO [03/30/22 6:44:41:24] Searching for commits reachable from 'origin/master'.
      INFO [03/30/22 6:44:41:24] The branch 'origin/master' has no matching commits.

@asbjornu
Copy link
Member

asbjornu commented Apr 1, 2022

I'm not sure what's going on. Are you able to reproduce this in a local clone of a public repository, @davidkeaveny?

@davidkeaveny
Copy link
Contributor Author

davidkeaveny commented Apr 5, 2022

I forked GitVersion and imported that repository into BitBucket Cloud, then created a minimal pipeline, and the wretched thing ran out of the box!

Using the exact same contents for GitVersion.yml and bitbucket-pipelines.yml on my original private repo, it still fails with the same error.

@davidkeaveny
Copy link
Contributor Author

In the end, I exported my develop branch from BitBucket Cloud, and created a new empty repo, to which I added a minimal pipeline and GitVersion.yml, verified that GitVersion ran as expected, then just imported the old repo into the new develop branch and verified that GitVersion was still working as expected. So I'm guessing there must have been something wrong with the original repo, but I've no idea what...

@davidkeaveny
Copy link
Contributor Author

davidkeaveny commented Apr 6, 2022

Looks like I got ahead of myself - as soon as I created a feature branch from develop and ran the pipeline, then the same error returned.

So to summarise, when building on Atlassian BitBucket Cloud Pipelines and clone: depth: full is set so that the whole repository is cloned:

  • if I build from master or develop, then GitVersion works as expected;
  • if I build from any other branch (e.g. feature/*) then I get the error Gitversion could not determine which branch to treat as the development branch (default is 'develop') nor release-able branch (default is 'main' or 'master'), either locally or remotely. Ensure the local clone and checkout match the requirements or considering using 'GitVersion Dynamic Repositories'

@davidkeaveny davidkeaveny reopened this Apr 6, 2022
@davidkeaveny
Copy link
Contributor Author

Would it help if I implemented a build agent for BitBucket Pipelines? That might help work around whatever limitation is causing this issue; I've got an initial version in https://github.com/davidkeaveny/GitVersion/tree/feature/add-bitbucket-build-agent.

@arturcic arturcic linked a pull request Apr 13, 2022 that will close this issue
5 tasks
@arturcic
Copy link
Member

Closed by #3069

@arturcic arturcic modified the milestones: 5.x, 5.10.0 Apr 13, 2022
@github-actions
Copy link

🎉 This issue has been resolved in version 5.10.0 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

@davidkeaveny
Copy link
Contributor Author

Confirmation from my BitBucket Pipelines execution showing that GitVersion 5.10.1 now executes and produces the desired output:

image

Many thanks for your help in getting the PR reviewed and up-to-scratch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants