Skip to content

Cannot generate version number on BitBucket Cloud Pipelines #3057

Closed
@davidkeaveny

Description

@davidkeaveny

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions