gitazure-devopspipelinegitversion

Azure DevOps task fails to checkout disabling shallow


In my Azure DevOps pipeline I'm using GitVersion to determine a version number for my software system using semantic versioning. At this time, the GitVersion task fails because my repo is shallow. To overcome this problem, I can add a fetchDepth of 0 to disable shallow clones, however... It fails:

Below is a fraction of my (Yuck Yaml) pipeline:

- checkout: self
  fetchDepth: 0
  fetchTags: true
  persistCredentials: true
  clean: false
  displayName: Checkout and clean

- script: git -C $(Pipeline.Workspace)/s rev-parse --is-shallow-repository
  displayName: Check

As you can see, I do a repo with fetchDepth of 0 but still, the following script (git -C...) reports the repo is shallow:

Log file in AzDo pipeline

How can I fetch from my repo with truely disabling shallow repository so GitVersion can do its job?


Solution

  • I could reproduce the issue if I set checkout with fetchDepth: 0, after several runs with fetchDepth set to 1. And I noticed the shallow file kept appearing in the .git directory when the issue was reproduced.

    Image

    For this, I tried to clean the pipeline workspace to make sure the .git folder in the source directory was removed before the checkout step.

    workspace:
      clean: all
    
    steps:
    # - script: sleep 30s
    - checkout: self
      fetchDepth: 0
      fetchTags: true
      persistCredentials: true
      clean: false
      displayName: Checkout and clean
    - script: |
        echo "================1. Check if shallow fetch================"
        git -C $(Pipeline.Workspace)/s rev-parse --is-shallow-repository
        echo "================2. Check YAML definition================"
        cat YAML/CheckoutShallow.yml
        echo "================3. Check shallow file in .git================"
        tree .git
      displayName: Check
    

    Or if you prefer, you may consider removing the shallow file with a simple script.

    - script: |
        if test -f "$(Build.SourcesDirectory)/.git/shallow"; then
          echo "Remove shallow file."
          rm "$(Build.SourcesDirectory)/.git/shallow"
        else
          echo "No shallow file found!"
        fi
      displayName: 'Clean shallow'