Azure / static-web-apps

Azure Static Web Apps. For bugs and feature requests, please create an issue in this repo. For community discussions, latest updates, kindly refer to the Discussions Tab. To know what's new in Static Web Apps, visit https://aka.ms/swa/ThisMonth
https://aka.ms/swa
MIT License
318 stars 53 forks source link

Cannot create subsequent releases using AzureStaticWebApp@0 while building via Oryx #1470

Open anime-shed opened 1 month ago

anime-shed commented 1 month ago

Describe the bug

I am using the AzureStaticWebApp@0 in my RELEASE pipeline, but on a subsequent releases I face an error Failed to create Release artifact directory

2024-05-09T18:50:49.5556994Z Creating artifacts directory: /home/ritesh/agent-1/_work/r37/a
2024-05-09T18:50:49.5684499Z Failed to create Release artifact directory /home/ritesh/agent-1/_work/r37/a with an exception Microsoft.VisualStudio.Services.Agent.Worker.Release.Artifacts.ArtifactDirectoryCreationFailedException: Failed to create Release artifact directory '/home/ritesh/agent-1/_work/r37/a'.
 ---> System.UnauthorizedAccessException: Access to the path '/home/ritesh/agent-1/_work/r37/a/_MyRepoCloned/nuxt.config.ts' 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.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
   --- End of inner exception stack trace ---
   at Microsoft.VisualStudio.Services.Agent.Worker.Release.ReleaseFileSystemManager.EnsureEmptyDirectory(String directoryPath, CancellationToken cancellationToken) in /home/vsts/work/1/s/src/Agent.Worker/Release/ReleaseFileSystemManager.cs:line 66
   at Microsoft.VisualStudio.Services.Agent.Worker.Release.ReleaseJobExtension.<>c__DisplayClass41_0.<CreateArtifactsFolder>b__1() in /home/vsts/work/1/s/src/Agent.Worker/Release/ReleaseJobExtension.cs:line 326
   at Microsoft.VisualStudio.Services.Agent.Worker.Release.RetryExecutor.Execute(Action action) in /home/vsts/work/1/s/src/Agent.Worker/Release/RetryExecutor.cs:line 41. Retrying the creation of Release artifact directory.
2024-05-09T18:50:49.5695823Z Creating artifacts directory: /home/ritesh/agent-1/_work/r37/a
2024-05-09T18:50:49.5710878Z Failed to create Release artifact directory /home/ritesh/agent-1/_work/r37/a with an exception Microsoft.VisualStudio.Services.Agent.Worker.Release.Artifacts.ArtifactDirectoryCreationFailedException: Failed to create Release artifact directory '/home/ritesh/agent-1/_work/r37/a'.

To Reproduce Steps to reproduce the behavior:

#Your build pipeline references a secret variable named ‘static.Token’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it secret. See https://go.microsoft.com/fwlink/?linkid=865972

steps:
- task: AzureStaticWebApp@0
  displayName: 'Static Web App: '
  inputs:
    workingDirectory: '$(System.DefaultWorkingDirectory)/_MyRepoCloned'
    app_build_command: 'npm i && npm run build'
    output_location: dist
    skip_app_build: false
    skip_api_build: true
    is_static_export: true
    verbose: false
    azure_static_web_apps_api_token: '$(static.Token)'

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Device info (if applicable):

Additional context What I have debugged is that after creating the folder _MyRepoCloned from a user account ritesh when Oryx starts to build for the first time using npm this file gets owned by root, causing the issue in the subsequent release.