How to add "AddPackage" permission in Azure Devops

70 Views Asked by At

I am using a self hosted windows agent to publish my build artifacts to the azure artifact feed since the artifacts are .zip file I am using UniversalPackages task given below.

- task: UniversalPackages@0
    displayName: 'Publish to Azure Artifact feed'
    inputs:
      command: 'publish'
      publishDirectory: '$(Build.ArtifactStagingDirectory)/files.zip'
      feedsToUsePublish: 'internal'
      vstsFeedPublish: 'kitagi'
      vstsFeedPackagePublish: 'testartifact'
      versionOption: 'custom'
      versionPublish: '1.0.3'
      publishedPackageVar: 'testartifact'

but after running the pipeline the artifact are published in pipeline but not in the feed as I am facing this error

{"@t":"2024-03-20T05:25:00.7229663Z","@m":"Processed 2 files from C:\\agent\\_work\\203\\s\\pkg successfully.","@i":"f0e0724e","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:00.722Z"}
{"@t":"2024-03-20T05:25:01.6889088Z","@m":"Uploaded 166,729 out of 2,499,906 bytes","@i":"e1ca3655","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:01.688Z"}
{"@t":"2024-03-20T05:25:01.6890283Z","@m":"Content upload is done!","@i":"3fa1b25b","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:01.689Z"}
{"@t":"2024-03-20T05:25:01.6907829Z","@m":"\nContent upload statistics:\nTotal Content: 5.0 MB\r\nPhysical Content Uploaded: 63.3 KB\r\nLogical Content Uploaded: 0.2 MB\r\nCompression Saved: 0.1 MB\r\nDeduplication Saved: 4.8 MB\r\nNumber of Chunks Uploaded: 4\r\nTotal Number of Chunks: 81\r\n","@i":"8af5a6ef","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:01.690Z"}
{"@t":"2024-03-20T05:25:01.7077933Z","@m":"Content pushed","@i":"a2f90a5e","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:01.707Z"}
{"@t":"2024-03-20T05:25:01.7099269Z","@m":"Adding package...","@i":"183e7e34","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:01.709Z"}
{"@t":"2024-03-20T05:25:02.1855344Z","@m":"ApplicationInsightsTelemetrySender correlated 1 events with X-TFS-Session 19a77432-1b56-4189-b726-de1c7662e9d8","@i":"09ca3bd4","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:02.185Z"}
{"@t":"2024-03-20T05:25:02.1865383Z","@m":***"An error occurred on the service. **User 'f3d5130b-1a1b-4c35-9703-4d5cb68bb1d9' lacks permission to complete this action. You need to have 'AddPackage'.","@i":"f4f95e05","@l":"Error","SourceContext":"ArtifactTool.Program","UtcTimestamp":"2024-03-20 05:25:02.186Z"}*****
##[error]Error: An unexpected error occurred while trying to push the package. Exit code(1) and error({"@t":"2024-03-20T05:24:58.8912620Z","@m":"ApplicationInsightsTelemetrySender will correlate events with X-TFS-Session 19a77432-1b56-4189-b726-de1c7662e9d8","@i":"259c7956","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:24:58.891Z"}
{"@t":"2024-03-20T05:24:59.9847087Z","@m":"Ensuring that the package does not yet exist...","@i":"40e01e14","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:24:59.984Z"}
{"@t":"2024-03-20T05:25:00.5541876Z","@m":"Package does not yet exist","@i":"c781eca5","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:00.554Z"}
{"@t":"2024-03-20T05:25:00.5557241Z","@m":"Pushing content...","@i":"3aa40378","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:00.555Z"}
{"@t":"2024-03-20T05:25:00.5731484Z","@m":"DedupManifestArtifactClient will correlate http requests with X-TFS-Session 19a77432-1b56-4189-b726-de1c7662e9d8","@i":"ec3fe6b7","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:00.573Z"}
{"@t":"2024-03-20T05:25:00.7219128Z","@m":"2 files processed.","@i":"5921802e","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:00.721Z"}
{"@t":"2024-03-20T05:25:00.7229663Z","@m":"Processed 2 files from C:\\agent\\_work\\203\\s\\pkg successfully.","@i":"f0e0724e","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:00.722Z"}
{"@t":"2024-03-20T05:25:01.6889088Z","@m":"Uploaded 166,729 out of 2,499,906 bytes","@i":"e1ca3655","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:01.688Z"}
{"@t":"2024-03-20T05:25:01.6890283Z","@m":"Content upload is done!","@i":"3fa1b25b","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:01.689Z"}
{"@t":"2024-03-20T05:25:01.6907829Z","@m":"\nContent upload statistics:\nTotal Content: 5.0 MB\r\nPhysical Content Uploaded: 63.3 KB\r\nLogical Content Uploaded: 0.2 MB\r\nCompression Saved: 0.1 MB\r\nDeduplication Saved: 4.8 MB\r\nNumber of Chunks Uploaded: 4\r\nTotal Number of Chunks: 81\r\n","@i":"8af5a6ef","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:01.690Z"}
{"@t":"2024-03-20T05:25:01.7077933Z","@m":"Content pushed","@i":"a2f90a5e","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:01.707Z"}
{"@t":"2024-03-20T05:25:01.7099269Z","@m":"Adding package...","@i":"183e7e34","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:01.709Z"}
{"@t":"2024-03-20T05:25:02.1855344Z","@m":"ApplicationInsightsTelemetrySender correlated 1 events with X-TFS-Session 19a77432-1b56-4189-b726-de1c7662e9d8","@i":"09ca3bd4","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2024-03-20 05:25:02.185Z"}
{"@t":"2024-03-20T05:25:02.1865383Z","@m":"An error occurred on the service. User 'f3d5130b-1a1b-4c35-9703-4d5cb68bb1d9' lacks permission to complete this action. You need to have 'AddPackage'.","@i":"f4f95e05","@l":"Error","SourceContext":"ArtifactTool.Program","UtcTimestamp":"2024-03-20 05:25:02.186Z"})
##[error]Packages failed to publish
Finishing: Publish to Azure Artifact feed
1

There are 1 best solutions below

0
Kevin Lu-MSFT On

"An error occurred on the service. User 'f3d5130b-1a1b-4c35-9703-4d5cb68bb1d9' lacks permission to complete this action. You need to have 'AddPackage'.","@i":"f4f95e05","@l":"Error","SourceContext":"ArtifactTool.Program","UtcTimestamp":"2024-03-20 05:25:02.186Z"})

When you use Publish Universal Package task in Azure Pipeline, it will use the Build Service Account to publish the package to feed.

To solve this issue, you can grant the Contributor role to the Build Service Account in Azure Artifacts -> Target Feed -> Settings -> Permissions.

Project level: Projectname Build Service(OrganizationName)

Organization level: Project Collection Build Service(OrganizationName)

For example:

enter image description here

For more detailed info, you can refer to these docs: Manage build service account permissions and Pipelines permissions

If you Azure Artifacts Feed and Azure Pipeline are in the different projects, you need to Disable the option: Limit job authorization scope to current project for non-release pipelines in Project Settings -> Settings