How to get Gitversion docker to get FullSemVer in Travis-CI

  docker, gitversion, travis-ci

I was trying to get FullSemVer value from GitVersion running on docker in Travis-CI build. My codes looks something like this in .travis.yml:

services:
  - docker

script:
  - docker pull gittools/gitversion:5.3.5-linux-alpine.3.10-x64-netcoreapp3.1
  - export GitVersion_FullSemVer=$(docker run --rm -v "$(pwd):/repo" gittools/gitversion:5.3.5-linux-alpine.3.10-x64-netcoreapp3.1 /repo -output json -showvariable FullSemVer)

Assume that I can successfully get the FullSemver value and assign to GitVersion_FullSemVer like above scripts. Then I could just:

before_deploy:
  - npm version $GitVersion_FullSemVer
deploy:
  # some deploy script

But in reality I get some nasty value:

$ echo $GitVersion_FullSemVer
INFO [04/16/21 4:16:37:44] Working directory: /repo INFO [04/16/21 4:16:37:47] Project root is: /repo/ INFO [04/16/21 4:16:37:47] DotGit directory is: /repo/.git INFO [04/16/21 4:16:37:50] Begin: Loading version variables from disk cache INFO [04/16/21 4:16:37:50] Cache file /repo/.git/gitversion_cache/FAA25BC3D78B47B1594DD5ADD897B1FB66D8C8D5.yml not found. INFO [04/16/21 4:16:37:50] End: Loading version variables from disk cache (Took: 1.31ms) INFO [04/16/21 4:16:37:58] Using latest commit on specified branch INFO [04/16/21 4:16:37:59] Begin: Getting branches containing the commit '8ca1e0b2c18ba8a5f64ce1455b11ff30c104555a'. INFO [04/16/21 4:16:37:59] Trying to find direct branches. INFO [04/16/21 4:16:37:59] No direct branches found, searching through all branches. INFO [04/16/21 4:16:37:59] Searching for commits reachable from 'hotfix/travis-ci-docker-gitversion'. INFO [04/16/21 4:16:37:61] End: Getting branches containing the commit '8ca1e0b2c18ba8a5f64ce1455b11ff30c104555a'. (Took: 23.18ms) ERROR [04/16/21 4:16:37:63] An unexpected error occurred: LibGit2Sharp.NotFoundException: object not found - no match for id (46b5a55fcfc6d1ff17ac25a9ac903af90a66d75d) at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result) at LibGit2Sharp.Core.Proxy.git_revwalk_next(RevWalkerHandle walker) at LibGit2Sharp.CommitLog.CommitEnumerator.MoveNext() at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext() at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source) at GitVersion.RepositoryMetadataProvider.GetBranchesContainingCommit(Commit commit, IEnumerable`1 branches, Boolean onlyTrackedBranches)+MoveNext() at GitVersion.Extensions.EnumerableExtensions.OnlyOrDefault[T](IEnumerable`1 source) in D:aGitVersionGitVersionsrcGitVersionCoreExtensionsEnumerableExtensions.cs:line 20 at GitVersion.GitVersionContextFactory.Init(Branch currentBranch, String commitId, Boolean onlyTrackedBranches) in D:aGitVersionGitVersionsrcGitVersionCoreCoreGitVersionContextFactory.cs:line 42 at GitVersion.GitVersionContextFactory.Create(GitVersionOptions gitVersionOptions) in D:aGitVersionGitVersionsrcGitVersionCoreCoreGitVersionContextFactory.cs:line 28 at GitVersion.GitVersionCoreModule.<>c__DisplayClass0_0.<RegisterTypes>b__3() in D:aGitVersionGitVersionsrcGitVersionCoreGitVersionCoreModule.cs:line 61 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:aGitVersionGitVersionsrcGitVersionCoreVersionCalculationNextVersionCalculator.cs:line 17 at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in D:aGitVersionGitVersionsrcGitVersionCoreVersionCalculationNextVersionCalculator.cs:line 32 at GitVersion.GitVersionTool.CalculateVersionVariables() in D:aGitVersionGitVersionsrcGitVersionCoreCoreGitVersionTool.cs:line 68 at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:aGitVersionGitVersionsrcGitVersionExeGitVersionExecutor.cs:line 59 INFO [04/16/21 4:16:37:63] Attempting to show the current git graph (please include in issue): INFO [04/16/21 4:16:37:63] Showing max of 100 commits INFO [04/16/21 4:16:37:63] Could not execute 'git log' due to the following error: System.IO.FileNotFoundException: The executable file 'git' could not be found. File name: 'git' ---> System.ComponentModel.Win32Exception (2): No such file or directory at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec) at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at GitVersion.Helpers.ProcessHelper.Start(ProcessStartInfo startInfo) in D:aGitVersionGitVersionsrcGitVersionCoreHelpersProcessHelper.cs:line 26 at GitVersion.Helpers.ProcessHelper.Start(ProcessStartInfo startInfo) in D:aGitVersionGitVersionsrcGitVersionCoreHelpersProcessHelper.cs:line 42 at GitVersion.Helpers.ProcessHelper.Run(Action`1 output, Action`1 errorOutput, TextReader input, String exe, String args, String workingDirectory, KeyValuePair`2[] environmentalVariables) in D:aGitVersionGitVersionsrcGitVersionCoreHelpersProcessHelper.cs:line 120 at GitVersion.Extensions.LibGitExtensions.DumpGraph(String workingDirectory, Action`1 writer, Nullable`1 maxCommits) in D:aGitVersionGitVersionsrcGitVersionCoreExtensionsLibGitExtensions.cs:line 86

(Sorry, I don’t know how to make line break on markdown’s code block, here is the actual Travis-CI link, see line 281).
If I just execute the following code on Travis-CI:

docker run --rm -v "$(pwd):/repo" gittools/gitversion:5.3.5-linux-alpine.3.10-x64-netcoreapp3.1 /repo

it will also return some long nasty string of value that I don’t understand (link here on line 287).
Please advise. Thank you.

Source: Docker Questions

LEAVE A COMMENT