microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.47k stars 2.6k forks source link

[BUG]: AzureStaticWebApp@0 gets permission denied error when executed on self-hosted agent #19356

Open matt-lethargic opened 9 months ago

matt-lethargic commented 9 months ago

New issue checklist

Task name

AzureStaticWebApp

Task version

0

Issue Description

When task is executed some files are created in Build.SourcesDirectory.

For me this is the app/public directory for a Hugo app, this is the output from the build process. When pipeline is executed on hosted agent each build gets clean workspace, so there are no output files from previous build. In this case everything is ok.

But when pipeline is executed on self-hosted agent the next build fails at git checkout task because git clean cannot remove output files which are generated within git workspace directory. Execution fails with many errors like this one:

##[error]System.UnauthorizedAccessException: Access to the path '/home/***/agent-1/_work/8/s/app/public/index.xml' is denied.

The reason is that files generated as output from the task are owned by different user than user under which agent is executed. This different user is an user under which Docker daemon is running, because as I've learned AzureStaticWebApp task is performed by running Docker container.

The public folder which is the output from Hugo is owned by root

Environment type (Please select at least one enviroment where you face this issue)

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

Ubuntu 20

Relevant log output

git version
git version 2.40.1
git lfs version
git-lfs/3.3.0 (GitHub; linux amd64; go 1.19.3)
git config --get remote.origin.url
##[warning]'git config --get remote.origin.url' failed with exit code: 1, output: ''
##[error]One or several exceptions have been occurred.
##[error]System.UnauthorizedAccessException: Access to the path '/home/***/agent-1/_work/8/s/app/public/index.xml' is denied.
 ---> System.IO.IOException: Permission denied
   --- End of inner exception stack trace ---
   at System.IO.FileSystem.DeleteFile(String fullPath)
   at System.IO.FileInfo.Delete()
   at Microsoft.VisualStudio.Services.Agent.Util.IOUtil.<>c__DisplayClass11_0.<DeleteDirectory>b__0(FileSystemInfo item) in /home/vsts/work/1/s/src/Agent.Sdk/Util/IOUtil.cs:line 152
   at System.Linq.Parallel.ForAllOperator`1.ForAllEnumerator`1.MoveNext(TInput& currentElement, Int32& currentKey)
   at System.Linq.Parallel.ForAllSpoolingTask`2.SpoolingWork()
   at System.Linq.Parallel.SpoolingTaskBase.Work()
   at System.Linq.Parallel.QueryTask.BaseWork(Object unused)
   at System.Linq.Parallel.QueryTask.RunTaskSynchronously(Object o)
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)

Full task logs with system.debug enabled

 [REPLACE THIS WITH YOUR INFORMATION] 

Repro steps

No response

github-actions[bot] commented 3 months ago

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

matt-lethargic commented 3 months ago

Still an issue