GitVersion icon indicating copy to clipboard operation
GitVersion copied to clipboard

[Docs] Azure Devops - Fetch Depth

Open dazinator opened this issue 2 years ago • 4 comments

For Azure devops build pipelines created later than a certain date, they started doing shallow clone's and subsequently this means the following gitversion AzDO tasks fail.

   - task: gitversion/setup@0
      displayName: Install GitVersion
      inputs:
        versionSpec: '5.11.1'

    - task: gitversion/execute@0
      displayName: Determine Version
      inputs:      

There is a gitversion docs page for configuring the different build servers but nothing about this for azure devops that I could see.

The important piece of info is here: https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/steps-checkout?view=azure-pipelines#shallow-fetch

image

It basically boils down to this, you need to add an intial checkout task to your yaml pipeline to control checkout behaviour and explicit set fetch depth to 0 (which means it won't do shallow fetch).

 steps:     
    # this is rewquired for gitversion
    - checkout: self
      fetchDepth: 0
      clean: true 

dazinator avatar Jun 27 '23 15:06 dazinator

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.

github-actions[bot] avatar Sep 26 '23 11:09 github-actions[bot]

This issue was closed because it has been stalled for 30 days with no activity. Thank you for your contributions

github-actions[bot] avatar Oct 27 '23 11:10 github-actions[bot]

A pull request documenting this would be merged in an instant. 🙏🏼

asbjornu avatar Oct 27 '23 11:10 asbjornu

I think The AzureDevops task should point instead to https://github.com/GitTools/actions/tree/main/docs/examples/azure as there we have the examples and docs

arturcic avatar Oct 27 '23 12:10 arturcic

Closing in favor of https://github.com/GitTools/GitVersion/issues/3937

arturcic avatar Mar 09 '24 09:03 arturcic

I get this problem even with fetchDepth: 0 setting. The problem occurs every time I start a pipeline run. When I re-run the job (Re-run failed tasks), it goes well.

    steps:
    - checkout: self
      clean: true
      fetchDepth: 0
      fetchTags: true
      submodules: recursive

mc0re avatar Jul 08 '24 13:07 mc0re

I also have this problem @mc0re - did you find a solution? It seems like every couple of years, Microsoft VSTS/AzureDevOps finds a way to break this feature. It broke in 2018 and 2022, and now 2024.

jzabroski avatar Aug 06 '24 15:08 jzabroski

@jzabroski In my case the issue was in using on-site agents and not cleaning them. There's a file in .git directory that tells Git it's working in shallow mode. The file is created by later jobs, using shallow checkout. Delete it after the checkout step - and it works. I'm afraid I can't recall the exact name of the file and I cannot look it up now, but it was obvious from the name.

mc0re avatar Aug 07 '24 08:08 mc0re