GitTools / GitVersion

From git log to SemVer in no time
https://gitversion.net/docs/
MIT License
2.86k stars 651 forks source link

[Docs] Azure Devops - Fetch Depth #3612

Closed dazinator closed 7 months ago

dazinator commented 1 year ago

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 
github-actions[bot] commented 1 year ago

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] commented 1 year ago

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

asbjornu commented 1 year ago

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

arturcic commented 1 year ago

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 commented 7 months ago

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

mc0re commented 3 months ago

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
jzabroski commented 2 months ago

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.

mc0re commented 2 months ago

@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.