This is my Yaml Pipeline Script
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/DockerImage.tar'
ArtifactName: 'Docker-Image'
publishLocation: 'Container'
This is the Error Logs
Fail to upload '/home/vsts/work/1/a/DockerImage.tar' due to 'Access to the path '/home/vsts/work/1/a/DockerImage.tar' is denied.'. System.UnauthorizedAccessException: Access to the path '/home/vsts/work/1/a/DockerImage.tar' is denied. ---> System.IO.IOException: Permission denied --- End of inner exception stack trace --- at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func
2 errorRewriter) at Interop.CheckIo(Error error, String path, Boolean isDirectory, Func
2 errorRewriter) at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode) at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize) at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize) at Microsoft.VisualStudio.Services.Agent.Worker.Build.FileContainerServer.UploadAsync(IAsyncCommandContext context, Int32 uploaderId, CancellationToken token) in /mnt/vss/_work/1/s/src/Agent.Worker/Build/FileContainerServer.cs:line 251
I tried Looking for how to give permission to my pipeline i was also using the Pipeline.workspace location to publish my artifacts but there also i got the same error. I am not sure how to give permission to my pipeline.
I am relatively new to Azure Devops platform.
Your issue is that you are using sudo
to save the file, which saves it under a different user context than the currently executing pipeline. The pipeline agent should have sufficient permissions on the agent to do everything you need. Running 'sudo' should not be necessary.
The following works:
trigger: none
pool:
vmImage: ubuntu-latest
steps:
- script: |
docker pull busybox
docker save busybox -o $(Build.ArtifactStagingDirectory)/DockerImage.tar
displayName: Docker Save Command
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/DockerImage.tar'
ArtifactName: 'Docker-Image'