Monday, January 29, 2024

[SOLVED] All *.sh files became CRLF in the cloudbuild drop output

Issue

The *.sh files will become windows CRLF EOF in the cloudbuild drop output.

I have set the .gitattributes with: text= and * -text and *.sh eol=lf on master branch.

And I have added all the files in my scripts folder with: git add --renormalize .\scripts in my branch. But the cloudbuild drop would still force the *.sh file into CRLF in the drop explorer.

git config --global --get core.autocrlf is input.

How to resolve this issue?


Solution

I can reproduce the same issue in Azure DevOps Pipeline.

The cause of the issue is that when we cloning the repo to Windows Agent, it will auto convert the LF to CRLF. Then when publishing the Drop Build Artifacts, it will show the CRLF EOL.

To solve this issue, you can run the command: git config --global core.autocrlf false before the git checkout step.

For example:

pool:
  vmImage: windows-latest

steps:
- script: git config --global  core.autocrlf false

- checkout: self

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.sourcesdirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

Then the files in the Drop Build Artifacts will keep the LF EOL.



Answered By - Kevin Lu-MSFT
Answer Checked By - Candace Johnson (WPSolving Volunteer)