Search code examples
githubazure-devopsnugetgithub-actionsazure-artifacts

GitHub Actions to push to Azure Artifacts: Unable to load the service index for source ' ' Response status code does not indicate success: 401 (unaut)


I wanted to create a Github workflow that push feed to Azure Artifacts. I carefully followed the article here and the tutorial here. However, I keep getting this error

error: Unable to load the service index for source https://pkgs.dev.azure.com/<org>/<proj>/_packaging/<proj>/nuget/v3/index.json. error: Response status code does not indicate success: 401 (Unauthorized).

I created a PAT for all accessible organizations, granted it full access and added it in my Github Action secrets just as the docs says but the error persists. Does anyone have idea what could be wrong here?


Solution

  • So the workflow is actually using another action actions/setup-dotnet@v1to build and publish the package. Turned out this action does not properly pass the personal access token as api key in the nuget push command. I created an issue here which was not resolved as at now. However, I was able to resolve the issue by directly adding --api-key ${{ secrets.GITHUB_TOKEN }} to dotnet nuget push command. My resulting command looks like:

    - name: 'dotnet publish'
      run: dotnet nuget push bin/Release/*.nupkg --api-key ${{ secrets.GITHUB_TOKEN }}
    

    This works for both Azure Artifacts and Github Registry.