Gitversion: Azure pipelines not finding version.

Created on 13 Oct 2019  路  10Comments  路  Source: GitTools/GitVersion

I am trying to use GitVersion in Azure pipelines but I am getting "Fallback base version: 0.1.0"

I can also see

"Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories"

but I really don't understand what I've done wrong as the tutorials I've followed seem to use the same config. Is this possibly caused by the /nofetch flag? I saw a similar post here https://github.com/GitTools/GitVersion/issues/1781

Sorry for the formatting, I'm not sure how to make the below look nicer.

Starting: GitVersion
==============================================================================
Task         : GitVersion Task
Description  : Easy Semantic Versioning (http://semver.org) for projects using Git
Version      : 5.0.1
Author       : GitVersion Contributors
Help         : See the [documentation](http://gitversion.readthedocs.org/en/latest/) for help
==============================================================================
[command]"C:\Program Files\dotnet\dotnet.exe" d:\a\_tasks\GitVersion_e5983830-3f75-11e5-82ed-81492570a08e\5.0.1\core\GitVersion.dll d:\a\1\s /output buildserver /nofetch /config d:\a\1\s
INFO [10/13/19 10:34:48:74] Working directory: d:\a\1\s
INFO [10/13/19 10:34:48:81] IsDynamicGitRepository: False
INFO [10/13/19 10:34:49:20] Returning Project Root from DotGitDirectory: d:\a\1\s\.git - d:\a\1\s
INFO [10/13/19 10:34:49:20] Running on Windows.
INFO [10/13/19 10:34:49:21] Applicable build agent found: 'VsoAgent'.
INFO [10/13/19 10:34:49:21] Branch from build environment: refs/heads/master
INFO [10/13/19 10:34:49:21] Begin: Normalizing git directory for branch 'refs/heads/master'
  INFO [10/13/19 10:34:49:33] One remote found (origin -> 'https://<companyName>.visualstudio.com/<companyName>.Core/_git/<companyName>.Core').
  INFO [10/13/19 10:34:49:34] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
  INFO [10/13/19 10:34:49:35] Creating local branch refs/heads/master
  INFO [10/13/19 10:34:49:39] HEAD points at branch 'refs/heads/master'.
  INFO [10/13/19 10:34:49:40] End: Normalizing git directory for branch 'refs/heads/master' (Took: 185.64ms)
  INFO [10/13/19 10:34:49:40] IsDynamicGitRepository: False
  INFO [10/13/19 10:34:49:40] Returning Project Root from DotGitDirectory: d:\a\1\s\.git - d:\a\1\s
  INFO [10/13/19 10:34:49:40] Project root is: d:\a\1\s
  INFO [10/13/19 10:34:49:40] DotGit directory is: d:\a\1\s\.git
  INFO [10/13/19 10:34:49:64] IsDynamicGitRepository: False
  INFO [10/13/19 10:34:49:64] Returning Project Root from DotGitDirectory: d:\a\1\s\.git - d:\a\1\s
  INFO [10/13/19 10:34:49:64] Begin: Loading version variables from disk cache
    INFO [10/13/19 10:34:49:65] Cache file d:\a\1\s\.git\gitversion_cache\960C173676C070F57801F3409A5FCA786F6A1EDC.yml not found.
  INFO [10/13/19 10:34:49:65] End: Loading version variables from disk cache (Took: 1.00ms)
  INFO [10/13/19 10:34:49:65] IsDynamicGitRepository: False
  INFO [10/13/19 10:34:49:65] Returning Project Root from DotGitDirectory: d:\a\1\s\.git - d:\a\1\s
  INFO [10/13/19 10:34:49:74] Using latest commit on specified branch
  INFO [10/13/19 10:34:49:83] Running against branch: master (19d7e5d6ecc45912c21bdee78d83b2a64900fb54)
  INFO [10/13/19 10:34:49:84] Begin: Calculating base versions
    INFO [10/13/19 10:34:49:89] Fallback base version: 0.1.0 with commit count source d84f0f3e7afa847087bdb471ba8bd5ec8dd80b48 (Incremented: None)
    INFO [10/13/19 10:34:50:09] Found multiple base versions which will produce the same SemVer (0.1.0), taking oldest source for commit counting (Fallback base version)
    INFO [10/13/19 10:34:50:09] Base version used: Fallback base version: 0.1.0 with commit count source d84f0f3e7afa847087bdb471ba8bd5ec8dd80b48 (Incremented: None)
  INFO [10/13/19 10:34:50:09] End: Calculating base versions (Took: 246.62ms)
  INFO [10/13/19 10:34:50:11] Skipping version increment
  INFO [10/13/19 10:34:50:12] 22 commits found between d84f0f3e7afa847087bdb471ba8bd5ec8dd80b48 and 19d7e5d6ecc45912c21bdee78d83b2a64900fb54
  INFO [10/13/19 10:34:50:16] Begin: Creating dictionary
  INFO [10/13/19 10:34:50:18] End: Creating dictionary (Took: 15.05ms)
  INFO [10/13/19 10:34:50:25] Begin: Storing version variables to cache file d:\a\1\s\.git\gitversion_cache\960C173676C070F57801F3409A5FCA786F6A1EDC.yml
  INFO [10/13/19 10:34:50:69] End: Storing version variables to cache file d:\a\1\s\.git\gitversion_cache\960C173676C070F57801F3409A5FCA786F6A1EDC.yml (Took: 445.76ms)
  INFO [10/13/19 10:34:50:69] Applicable build agent found: 'VsoAgent'.
Executing GenerateSetVersionMessage for 'VsoAgent'.
Executing GenerateBuildLogOutput for 'VsoAgent'.
##[section]Async Command Start: Update Build Number
Update build number to 0.1.0+22 for build 251
##[section]Async Command End: Update Build Number
##[section]Finishing: GitVersion

My GitVersion.yml file:

mode: Mainline
next-version: 1.0.0 
branches:
    feature:
        tag: alpha
    master:
        tag: ''
ignore:
  sha: []

And my build task on Azure:

# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps: 

- task: GitVersion@5
  displayName: GitVersion
  inputs:
    preferBundledVersion: false
- task: DotNetCoreCLI@2
  displayName: 'Build solution using DotNetCoreCLI'
  inputs:
    command: 'build'
    projects: |
     $(solution)
    arguments: '--configuration $(BuildConfiguration) /p:Version=$(GitVersion.NuGetVersion)'
    versioningScheme: byBuildNumber

- task: DotNetCoreCLI@2
  displayName: 'Create NuGet packages for solution using DotNetCoreCLI'
  inputs:
    command: 'pack'
    nobuild: true
    projects: |
     $(solution)
    versioningScheme: byEnvVar
    versionEnvVar: GitVersion.NuGetVersion

- task: DotNetCoreCLI@2
  displayName: 'Publish NuGet package'
  inputs:
    command: push
    publishVstsFeed: Core
    versioningScheme: byBuildNumber

When I view my gitversion settings locally it seems to be working fine:

$ gitversion
{
  "Major":1,
  "Minor":0,
  "Patch":11,
  "PreReleaseTag":".15",
  "PreReleaseTagWithDash":"",
  "PreReleaseLabel":"",
  "PreReleaseNumber":"",
  "WeightedPreReleaseNumber":"",
  "BuildMetaData":"",
  "BuildMetaDataPadded":"",
  "FullBuildMetaData":"Branch.master.Sha.eb7b3cdd5de32fe2de9982ef02b249575a1350eb",
  "MajorMinorPatch":"1.0.11",
  "SemVer":"1.0.11",
  "LegacySemVer":"1.0.11",
  "LegacySemVerPadded":"1.0.11",
  "AssemblySemVer":"1.0.11.0",
  "AssemblySemFileVer":"1.0.11.0",
  "FullSemVer":"1.0.11",
  "InformationalVersion":"1.0.11+Branch.master.Sha.eb7b3cdd5de32fe2de9982ef02b249575a1350eb",
  "BranchName":"master",
  "Sha":"eb7b3cdd5de32fe2de9982ef02b249575a1350eb",
  "ShortSha":"eb7b3cd",
  "NuGetVersionV2":"1.0.11",
  "NuGetVersion":"1.0.11",
  "NuGetPreReleaseTagV2":"",
  "NuGetPreReleaseTag":"",
  "VersionSourceSha":"d84f0f3e7afa847087bdb471ba8bd5ec8dd80b48",
  "CommitsSinceVersionSource":15,
  "CommitsSinceVersionSourcePadded":"0015",
  "CommitDate":"2019-10-11"
}

All of the tutorials I've seen to setup Azure Pipelines have used this configuration...

stale

Most helpful comment

For anyone following along, I attempted to get buildserver environment variables working with the following in my YAML:

- task: gitversion-setup@5
  inputs:
    versionSpec: '5.1.2'
- task: gitversion-execute@5
  inputs:
    additionalArguments: '/output buildserver'

This didn't work, as the gitversion-execute@5 task already adds /output json to the commandline. However, all this is doing is installing dotnet global tools anyway, so for a more robust way of doing things, try the following:

- task: DotNetCoreCLI@2
  displayName: 'Install gitversion'
  inputs:
    command: 'custom'
    custom: 'tool'
    arguments: 'install -g gitversion.tool'
- task: DotNetCoreCLI@2
  displayName: 'Gitversion setup'
  inputs:
    command: 'custom'
    custom: 'gitversion'
    arguments: '/output buildserver'

This works fine and for me gives correct results. Assuming you already have dotnet core installed on your agent, natively or with the UseDotNet@2 task.

All 10 comments

I had the same problem. I switched to installing and using GitVersion.CommandLine 5.0.1 via PowerShell in Azure Pipelines. Granted, I'm also manually updating projects in PowerShell too, so it's not entirely a plug-and-play solution. It seems to work fine.

I reverted to the GitVersion@4 task which seems to work well on windows but not on linux

Can you try this version https://marketplace.visualstudio.com/items?itemName=gittools.usegitversion

I've tested this version against basically same problem when GitVersion Task v5.0.1 in Azure DevOps Pipeline ignored the instruction from commits and calculated the same version over and over again no matter what I did with the master branch.

This version installs GitVersion task v5.1.2 and it fixed my problem. I'm wondering how propagate this solution into build-in task in Azure DevOps. :-/

I'm getting the same issue, it's been driving me crazy all day until I finally realised the issue was the GitVersion@5 task. Seems like it's lagging behind the release and contains bugs that have been fixed in mainline already? Shame, because it's very convenient to have it as task. Perhaps someone should consider removing the task from the marketplace until it's fixed?

@nizmow, unfortunately we cannot remove from marketplace as the old version is still used. As a workaround, to not break the older usages, we publish new extensions with different names. Currently the one that is currently maitained is https://marketplace.visualstudio.com/items?itemName=gittools.gittools.

That makes sense! I've installed that tool and I see it's running off the dotnet tool version now, which hopefully fixes compatibility going forward. Unfortunately it's not a drop-in replacement as it no longer sets Azure Devops environment variables automatically, meaning we'll need to wire up a script to the JSON output which is what I was hoping to avoid.

Also, if it's not possible to remove things from the marketplace it might be a good idea to consider renaming them, if that's possible. I got quite lost:

image

:)

For anyone following along, I attempted to get buildserver environment variables working with the following in my YAML:

- task: gitversion-setup@5
  inputs:
    versionSpec: '5.1.2'
- task: gitversion-execute@5
  inputs:
    additionalArguments: '/output buildserver'

This didn't work, as the gitversion-execute@5 task already adds /output json to the commandline. However, all this is doing is installing dotnet global tools anyway, so for a more robust way of doing things, try the following:

- task: DotNetCoreCLI@2
  displayName: 'Install gitversion'
  inputs:
    command: 'custom'
    custom: 'tool'
    arguments: 'install -g gitversion.tool'
- task: DotNetCoreCLI@2
  displayName: 'Gitversion setup'
  inputs:
    command: 'custom'
    custom: 'gitversion'
    arguments: '/output buildserver'

This works fine and for me gives correct results. Assuming you already have dotnet core installed on your agent, natively or with the UseDotNet@2 task.

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions.

I resolved the same issue by specifying value for optional "Config file" field in Azure pipeline task the same as default one - GitVersion.yml
without this I see the command in the log has wrong config path:
....\GitVersion.exe C:Build_Agents\1_work\970\s /output buildserver /nofetch /config C:Build_Agents\1_work\970\s

Was this page helpful?
0 / 5 - 0 ratings