Azure pipeline fails build when a git rename is used

Issue

Pretty much as the title suggests.

I have used a git rename command to update the filename of a JavaScript file. This has then been committed successfully to the repo from my local machine to GitHub.

This commit then triggers the Azure pipeline to initiate, however the build fails stating that it could not copy the javascript file in question as it cannot be found stating the old name. This seems to suggest that Azure is not pulling down the latest code before it starts to build is there something that needs to be added to the pipeline yaml to force an update?

trigger:
- master

pr:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: [email protected]

- task: [email protected]
  inputs:
    restoreSolution: '$(solution)'

# Run SonarCloud Prep
- task: [email protected]
  inputs:
    SonarCloud: 'SonarCloud'
    organization: 'myorg'
    scannerMode: 'MSBuild'
    projectKey: 'myapp'
    projectName: 'myappname'

- task: [email protected]
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: [email protected]
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

# Run SonarCloud Analyser

- task: [email protected]

# Run SonarCloud Publish 

- task: [email protected]
  inputs:
    pollingTimeoutSec: '300'

[UPDATE]

The rename command I am referring too above is actually just the git move command for clarity.

I have since checked that the repo is up to date both locally and in the remote. I can see that the file has the new name in the repo. Azure still does not seem to pull or recognise this change despite picking up the commit and starting the pipeline job.

In response to this I created a dummy file with the old name, committed this and the Azure pipeline succeeded. I then decided to run a delete command from git to remove the dummy file, this then triggered the pipeline once again which has also failed as before.

This would suggest that Azure is not updating itself when running VSBuild. Surely this is not a bug as I would imagine the inability to rename or even delete files in a repo would be a pretty massive problem across Azure.

The error is below:

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VisualStudio\v17.0\Web\Microsoft.Web.Publishing.targets(2672,5): Error : Copying file Scripts\diarysearch-2.0.11.js to obj\Release\Package\PackageTmp\Scripts\diarysearch-2.0.11.js failed. Could not find file ‘Scripts\diarysearch-2.0.11.js’.

Solution

OK so it turns out that this is technically a Visual Studio issue. The git rename (move command) has worked as expected and VS will build and successfully run the solution. However, since the project file is not updated with the new name, this is why the Azure pipeline fails.

I am not sure how the project in VS can successfully build without updating the project file but this seems to be where the problem stems from.

So the solution is to basically remove and re-add the file from the VS project and re-commit.

Answered By – David Hirst

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published