Skip to content

Cache broken with GitVersionTask 3.6.0 #942

Closed

Description

@tpluscode

I've just updated the MSBuild task package and apparently the cache is broken. Each target (WriteVersionInfoToBuildLog, WriteVersionInfoToBuildLog and GitVersion) in each built project recalculates the version number from scratch. Every time I see

Cache file C:\TeamCity\buildAgent\work\aaa244402599d927\.git\gitversion_cache\XYZ123.yml not found

And every time (during one build) the XYZ123 part is different. Worked good in version 3.5.4

Activity

  1. Martin-Andersen commented on Jul 14, 2016

    @Martin-Andersen

    @tpluscode glad I am not alone and not crazy. I am getting the exact same error
    [WriteVersionInfoToBuildLog] INFO [07/14/16 13:55:32:72] Cache file C:\TeamCity\buildAgent\work\e21746ec702e5b5d\.git\gitversion_cache\3012A3203E0BBA59F13642534D34033F6E301B69.yml not found.

    It takes forever when the cache is not working.

  2. DanielRose commented on Jul 14, 2016

    @DanielRose
    Contributor

    I have the same problem here. My build time went from MSBuild (3m:08s) to MSBuild (2h:04m:52s)!

    Even while building an assembly, the name of the cache file keeps on changing for every step:
    [WriteVersionInfoToBuildLog] INFO [07/13/16 10:42:19:40] Cache file C:\TeamCity_BuildAgent_2\work\60f2387b524bacc3\.git\gitversion_cache\B979AEEFD2C8836D2DD487256DFC4D03DFE097D1.yml not found.
    [UpdateAssemblyInfo] INFO [07/13/16 10:42:51:60] Cache file C:\TeamCity_BuildAgent_2\work\60f2387b524bacc3\.git\gitversion_cache\4641D2244564FA2AAB7EE360234E2E4AD9544A41.yml not found.
    [GetVersion] INFO [07/13/16 10:43:17:57] Cache file C:\TeamCity_BuildAgent_2\work\60f2387b524bacc3\.git\gitversion_cache\4F5D3967671A88C07685ED01CF8CCF4AC536CD7C.yml not found.

  3. JakeGinnivan commented on Jul 14, 2016

    @JakeGinnivan
    Contributor

    Hey, thanks for posting the issue.

    Not sure why this is happening, the code to calculate the hash is:

    var ticks = fileSystem.GetLastDirectoryWrite(Path.Combine(gitDir, "refs"));
    var configPath = Path.Combine(repo.GetRepositoryDirectory(), "GitVersionConfig.yaml");
    var configText = fileSystem.Exists(configPath) ? fileSystem.ReadAllText(configPath) : null;
    var configHash = configText != null ? GetHash(configText) : null;
    return string.Join(":", gitDir, repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks, configHash);
    

    The result is then hashed. As far as I know the only change is including the config file contents in the hash. Thoughts @asbjornu ?

  4. JakeGinnivan commented on Jul 17, 2016

    @JakeGinnivan
    Contributor

    Can you try 3.6.1, we received a PR which cleaned up and fixed some issues around cache.

  5. DanielRose commented on Jul 18, 2016

    @DanielRose
    Contributor

    Still broken:

    [WriteVersionInfoToBuildLog]   INFO [07/18/16 15:04:21:19] Cache file C:\TeamCity_BuildAgent_2\work\60f2387b524bacc3\.git\gitversion_cache\C29370840A305E08427BF70EDB4606F5D5CEE775.yml not found.
    [UpdateAssemblyInfo]   INFO [07/18/16 15:04:53:64] Cache file C:\TeamCity_BuildAgent_2\work\60f2387b524bacc3\.git\gitversion_cache\5D1DF19B99D8DA89FB856708DB2FC6C5037E0962.yml not found.
    [GetVersion]   INFO [07/18/16 15:05:19:65] Cache file C:\TeamCity_BuildAgent_2\work\60f2387b524bacc3\.git\gitversion_cache\863886002D4EC50937D970DD5EE8B93E9ECF5376.yml not found.
    
  6. DanielRose commented on Jul 20, 2016

    @DanielRose
    Contributor

    @JakeGinnivan I made a local build of GitVersion, where I added a bunch of debug info:

    [WriteVersionInfoToBuildLog] INFO [07/20/16 12:30:33:24] Applicable build agent found: 'TeamCity'.
    [WriteVersionInfoToBuildLog] INFO [07/20/16 12:30:33:24] Branch from build environment: refs/heads/master
    [WriteVersionInfoToBuildLog] INFO [07/20/16 12:30:33:40] IsDynamicGitRepository: False
    [WriteVersionInfoToBuildLog] INFO [07/20/16 12:30:33:40] Returning Project Root from DotGitDirectory: C:\TeamCity_BuildAgent_1\work\a458f20b6997ff65\.git - C:\TeamCity_BuildAgent_1\work\a458f20b6997ff65
    [WriteVersionInfoToBuildLog] INFO [07/20/16 12:30:33:40] Project root is: C:\TeamCity_BuildAgent_1\work\a458f20b6997ff65
    [WriteVersionInfoToBuildLog] INFO [07/20/16 12:30:33:40] DotGit directory is: C:\TeamCity_BuildAgent_1\work\a458f20b6997ff65\.git
    [WriteVersionInfoToBuildLog] INFO [07/20/16 12:30:33:40] Begin: Creating cache key
    [WriteVersionInfoToBuildLog]   INFO [07/20/16 12:30:33:40] dotGitDirectory: C:\TeamCity_BuildAgent_1\work\a458f20b6997ff65\.git
    [WriteVersionInfoToBuildLog]   INFO [07/20/16 12:30:33:40] fileSystem.Type: GitVersion.Helpers.FileSystem
    [WriteVersionInfoToBuildLog]   INFO [07/20/16 12:30:33:41] lastWriteDirectory: C:\TeamCity_BuildAgent_1\work\a458f20b6997ff65\.git\refs\heads at 2016-07-20T10:30:33.3694796Z
    [WriteVersionInfoToBuildLog]   INFO [07/20/16 12:30:33:42] lastGitRefsChangedTicks: 636046074333694796
    [WriteVersionInfoToBuildLog]   INFO [07/20/16 12:30:33:42] gitSystemHash: F5EE0BFC8A9ED77A73138C9758BBDB94582F334E
    [WriteVersionInfoToBuildLog]   INFO [07/20/16 12:30:33:42] IsDynamicGitRepository: False
    [WriteVersionInfoToBuildLog]   INFO [07/20/16 12:30:33:42] Returning Project Root from DotGitDirectory: C:\TeamCity_BuildAgent_1\work\a458f20b6997ff65\.git - C:\TeamCity_BuildAgent_1\work\a458f20b6997ff65
    [WriteVersionInfoToBuildLog]   INFO [07/20/16 12:30:33:42] configFileHash: 
    [WriteVersionInfoToBuildLog]   INFO [07/20/16 12:30:33:42] repositorySnapshotHash: 9DC5F0788F5E28502467DE855A9B70A9E678F540
    [WriteVersionInfoToBuildLog]   INFO [07/20/16 12:30:33:43] overrideConfigHash: 
    [WriteVersionInfoToBuildLog]   INFO [07/20/16 12:30:33:43] compositeHash: 745008D89B2C3CF1ABDA43F572E94F48830177F8
    [WriteVersionInfoToBuildLog] INFO [07/20/16 12:30:33:43] End: Creating cache key (Took: 26.00ms)
    
    
    [UpdateAssemblyInfo] INFO [07/20/16 12:30:33:59] Applicable build agent found: 'TeamCity'.
    [UpdateAssemblyInfo] INFO [07/20/16 12:30:33:59] Branch from build environment: refs/heads/master
    [UpdateAssemblyInfo] INFO [07/20/16 12:30:33:61] IsDynamicGitRepository: False
    [UpdateAssemblyInfo] INFO [07/20/16 12:30:33:62] Returning Project Root from DotGitDirectory: C:\TeamCity_BuildAgent_1\work\a458f20b6997ff65\.git - C:\TeamCity_BuildAgent_1\work\a458f20b6997ff65
    [UpdateAssemblyInfo] INFO [07/20/16 12:30:33:62] Project root is: C:\TeamCity_BuildAgent_1\work\a458f20b6997ff65
    [UpdateAssemblyInfo] INFO [07/20/16 12:30:33:62] DotGit directory is: C:\TeamCity_BuildAgent_1\work\a458f20b6997ff65\.git
    [UpdateAssemblyInfo] INFO [07/20/16 12:30:33:62] Begin: Creating cache key
    [UpdateAssemblyInfo]   INFO [07/20/16 12:30:33:62] dotGitDirectory: C:\TeamCity_BuildAgent_1\work\a458f20b6997ff65\.git
    [UpdateAssemblyInfo]   INFO [07/20/16 12:30:33:62] fileSystem.Type: GitVersion.Helpers.FileSystem
    [UpdateAssemblyInfo]   INFO [07/20/16 12:30:33:62] lastWriteDirectory: C:\TeamCity_BuildAgent_1\work\a458f20b6997ff65\.git\refs\heads at 2016-07-20T10:30:33.6024930Z
    [UpdateAssemblyInfo]   INFO [07/20/16 12:30:33:62] lastGitRefsChangedTicks: 636046074336024930
    [UpdateAssemblyInfo]   INFO [07/20/16 12:30:33:62] gitSystemHash: 8EDD4CCE752764B9B7FA39DD136356CA4A3A1A36
    [UpdateAssemblyInfo]   INFO [07/20/16 12:30:33:62] IsDynamicGitRepository: False
    [UpdateAssemblyInfo]   INFO [07/20/16 12:30:33:62] Returning Project Root from DotGitDirectory: C:\TeamCity_BuildAgent_1\work\a458f20b6997ff65\.git - C:\TeamCity_BuildAgent_1\work\a458f20b6997ff65
    [UpdateAssemblyInfo]   INFO [07/20/16 12:30:33:62] configFileHash: 
    [UpdateAssemblyInfo]   INFO [07/20/16 12:30:33:62] repositorySnapshotHash: 9DC5F0788F5E28502467DE855A9B70A9E678F540
    [UpdateAssemblyInfo]   INFO [07/20/16 12:30:33:62] overrideConfigHash: 
    [UpdateAssemblyInfo]   INFO [07/20/16 12:30:33:62] compositeHash: 183C0614646EBAE4F8EB31BE8ADC17B4A74F488D
    [UpdateAssemblyInfo] INFO [07/20/16 12:30:33:62] End: Creating cache key (Took: 8.00ms)
    

    The difference is when getting the last directory write. If you look at the timestamps, the write to .git\refs\heads happens somewhere between Branch from build environment: refs/heads/master and IsDynamicGitRepository: False

  7. DanielRose commented on Jul 20, 2016

    @DanielRose
    Contributor

    After some more tests: In GitPreparer.Initialise(), it calls GitRepositoryHelper.NormalizeGitDirectory() This method modifies the repository, which causes the cache to fail.

    It is a side effect of commit acce06c: the git directory is always normalized in a build server.

  8. tofutim commented on Jul 20, 2016

    @tofutim
    Contributor

    I have the problem too. It just happened that I was finally able to get my big solution into TeamCity right as 3.6.0 was available.

  9. tofutim commented on Jul 20, 2016

    @tofutim
    Contributor

    Seems like the problem persists in 3.6.1 - my builds are taking 20 min instead of a few minutes or less\

  10. JakeGinnivan commented on Jul 21, 2016

    @JakeGinnivan
    Contributor

    Awesome investigation @DanielRose

    If someone wants to pick this up that would be great.

  11. added a commit that references this issue on Jul 21, 2016
  12. DanielRose commented on Jul 21, 2016

    @DanielRose
    Contributor

    @tofutim Yes, that is what is being run. However, I don't understand the reason for that. Perhaps it is necessary to run that (once?) for dynamic repositories?

  13. 8 remaining items

  14. JakeGinnivan commented on Jul 26, 2016

    @JakeGinnivan
    Contributor

    Releasing 3.6.2 now. Thanks everyone for your help!

  15. DanielRose commented on Jul 27, 2016

    @DanielRose
    Contributor

    Updated to 3.6.2. Cache is working again on my build server. Thanks!

  16. nzrytmn commented on Jan 31, 2017

    @nzrytmn

    Hi everybody, i have still same problem with 3.6.5 version on tfs build server. I got same error with extension task , than i tried to add a commandline task and call gitversion.exe by command prompt and i got same error again.

    C:\agent_work\3\s.git\gitversion_cache\93DBD2FCAC2BADF8F53E06EE747571BA784376DF.yml not found

    .
    Because of this error, gitversion.exe never can't calculate the real version number, it always increase version number added by tag for each release.

    Do you have a suggestion? Am i have to back an older version recommended above ?

  17. asbjornu commented on Jan 31, 2017

    @asbjornu
    Member

    @nzrytmn: GitVersion should calculate the same version number with or without the cache. The only thing the cache should affect, is performance. If you're experiencing different version numbering depending, I would be inclined to conclude that that's another issue.

    Also, the line you've quoted is not an error, but expected behaviour if the version should infact change. If running GitVersion on the same commit several times in a row results in the same cache miss being logged, that's a problem, but as I said, that should not affect the version calculation.

  18. nzrytmn commented on Feb 6, 2017

    @nzrytmn

    Thanks for information @asbjornu , yes i know it is not an error, but "not found" message makes me feel something is not correct; by the way the main problem is the version number is not increasing that i expect.
    I am using gitflow for branching management and these are the steps i did; pls let me know if i did something wrong:
    1- Tag the base version as 1.2.0
    2- Create a release from this branch and deployed (version number is still 1.2.0)
    3- Create two feature branches and add new features. Merge with develop branch.
    4- Create a release branch from develop branch and deploy (version number is 1.2.1)
    (until here everything is ok, this is what i expect)
    5- Create new feature branches and add new features. Merge with develop branch.
    6- Create a release branch from develop branch and deploy (version number is still 1.2.1)
    (this is unexpected for me , because i added new features and i expect version will be changed)

    For my perspective the problem is version tool always calculates version number from base tag and because of this it is calculating same version for each release, it couldn't keep mind the old releases were deployed with same version it gave,

    gitversionresult

  19. asbjornu commented on Feb 6, 2017

    @asbjornu
    Member

    @nzrytmn: What versioning mode are you using? If it's ContinuousDelivery, what you see is expected. Every release is expected to have an associated tag. If you want the behaviour you see in develop, where the minor version is incremented automatically, to also apply to all other branches, you need to switch to mode: ContinuousDeployment.

  20. nzrytmn commented on Feb 8, 2017

    @nzrytmn

    @asbjornu I tried both mode, but it is calculating same version number for each release. But you are right, it may be because of my configuration settings. This is my GitVersion.yml file for one of my samples.

    branches: {
      master:
        regex: master
        mode: ContinuousDeployment
        tag: ''
        increment: Patch
        prevent-increment-of-merged-branch-version: true
        track-merge-target: false
        tracks-release-branches: false
        is-release-branch: false
      release:
        regex: release?[/-]
        mode: ContinuousDeployment
        tag: beta
        increment: Patch
        prevent-increment-of-merged-branch-version: true
        track-merge-target: false
        tracks-release-branches: false
        is-release-branch: true
      feature:
        regex: feature?[/-]
        mode: ContinuousDeployment
        tag: useBranchName
        increment: Inherit
        prevent-increment-of-merged-branch-version: false
        track-merge-target: false
        tracks-release-branches: false
        is-release-branch: false
      pull-request:
        regex: (pull|pull\-requests|pr)[/-]
        mode: ContinuousDeployment
        tag: PullRequest
        increment: Inherit
        prevent-increment-of-merged-branch-version: false
        tag-number-pattern: '[/-](?<number>\d+)[-/]'
        track-merge-target: false
        tracks-release-branches: false
        is-release-branch: false
      hotfix:
        regex: hotfix(es)?[/-]
        mode: ContinuousDeployment
        tag: beta
        increment: Patch
        prevent-increment-of-merged-branch-version: false
        track-merge-target: false
        tracks-release-branches: false
        is-release-branch: false
      support:
        regex: support[/-]
        mode: ContinuousDeployment
        tag: ''
        increment: Patch
        prevent-increment-of-merged-branch-version: true
        track-merge-target: false
        tracks-release-branches: false
        is-release-branch: false
      develop:
        regex: dev(elop)?(ment)?$
        mode: ContinuousDeployment
        tag: unstable
        increment: Minor
        prevent-increment-of-merged-branch-version: false
        track-merge-target: true
        tracks-release-branches: true
        is-release-branch: false
    }
    next-version: 1.2
    assembly-versioning-scheme: MajorMinorPatch
    assembly-informational-format: '{InformationalVersion}'
    mode: ContinuousDeployment
    increment: Inherit
    continuous-delivery-fallback-tag: ci
    tag-prefix: '[vV]'
    major-version-bump-message: '\+semver:\s?(breaking|major)'
    minor-version-bump-message: '\+semver:\s?(feature|minor)'
    patch-version-bump-message: '\+semver:\s?(fix|patch)'
    no-bump-message: '\+semver:\s?(none|skip)'
    legacy-semver-padding: 4
    build-metadata-padding: 4
    commits-since-version-source-padding: 4
    commit-message-incrementing: Enabled
    ignore:
      sha: []
      commits-before: yyyy-MM-ddTHH:mm:ss
  21. asbjornu commented on Feb 9, 2017

    @asbjornu
    Member

    @nzrytmn: Can you please try deleting the GitVersion.yml file and see how GitVersion behaves then?

  22. dsadikone commented on Jul 12, 2017

    @dsadikone

    @nzrytmn I am experiencing a basically identical issue, did you ever resolve it?

  23. fenneh commented on Sep 7, 2017

    @fenneh

    Having the exact same issues running 3.6.4. Nothing in the working directory is changing in-between TeamCity builds, the .yml used for the cache can't be found and GitVersion will go off and re-calculate a repo. Taking a build from 4 minutes to 33 minutes.

  24. asbjornu commented on Sep 7, 2017

    @asbjornu
    Member

    @fenneh: Can you please upgrade to v4 beta 12 and let us know if that fixes the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions