This Wednesday when I arrived at work, all our builds in Visual Studio Online (VSO) had failed and no new builds were able to complete. They all failed with "Access denied" errors on specific files. As VSO fails for wierd reasons some times and we had no hurry we just let it sit for a couple of hours to see if the error corrected itself. 

Unfortunately, it did not. So at lunch time we started investigating and soon found out that the VSO team made an update to the build servers the same day. Nothing in the change log seemed to relate to the issue so we continued to investigate.

It seemed that we could create new file (e.g. minified builds of our JS code) but could not update existing files (e.g. inject said minified code into our index.html file). The same build tasks that did this in VSO worked perfectly on our local machines.

Some time passed. Google gave us nothing and the builds were still not working. As a test I changed my local index.html file to "read only" and tried to run the build task locally. Voila! Gulp showed the same "Access denied" error. As the next step I added a PowerShell-script build step just before our Gulp script, which removed the "read only" attribute from our index.html file. The build completed successfully! 

So here you go, a PowerShell-script that removes the read only attribute from ALL files in the folder that VSO uses for checkouts:

Get-ChildItem "$(Agent.BuildDirectory)" -Recurse |
    Where-Object {$_.GetType().ToString() -eq "System.IO.FileInfo"} |
    Set-ItemProperty -Name IsReadOnly -Value $false

How to use it? 

  1. Edit the build definition of your build
  2. Click on "Add build step..."
  3. Select "Utility" and click on "Add" next to "PowerShell++" 
  4. Close the "Add build step..." modal and drag the new PowerShell++ step to the top of your build definition
  5. In the right side panel, set "Type" to "Inline script" and paste the code above in the "Script" field
  6. Click on Save and enjoy working builds (at least for now...)

Comment