'Git Checkout fails due to long file path names in the Azure DevOps yaml build pipeline

I have the Unity project code in Azure DevOps Repos and configured the below yaml pipeline to build the Unity project.

trigger: 

- none

stages: 

  - stage: Build

    displayName: Unity Build

    jobs:

    - job: 'UnityBuild'

      displayName: 'Build the Unity application'

      pool:

        name: XXXXXXXXX

      steps:
        - checkout: none
        - script: "git config system core.longpaths true"
        - checkout: self

        - task: UnityBuildTask@3

          inputs:

            buildTarget: 'standalone'

            unityProjectPath: 'XXXXXXXXXX'

            outputPath: '$(Build.BinariesDirectory)'

            outputFileName: 'Standalone'

        - task: UnityGetProjectVersionTask@1

          inputs:

            unityProjectPath: 'XXXXXXXXXX'

        - task: CopyFiles@2

          inputs:

            SourceFolder: '$(Build.BinariesDirectory)'

            Contents: '**'

            TargetFolder: '$(Build.ArtifactStagingDirectory)'

        - task: PublishBuildArtifacts@1

          inputs:

            PathtoPublish: '$(Build.ArtifactStagingDirectory)'

            ArtifactName: 'drop'

            publishLocation: 'Container'

Whenever I ran the yaml build pipeline, the build failed before it even executed unity build tasks due to file path name length restrictions.

How to fix the issue of file path names being too long in the Azure DevOps YAML pipeline?



Solution 1:[1]

You can run a script before "checkout" that tells Git.exe how to handle long paths (i.e. git config --system core.longpaths true).

See here.

Solution 2:[2]

If the agent is running on your own Windows server, then you'll need to configure the server to Enable Long Paths support.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shayki Abramczyk
Solution 2 Vince Bowdren