Home: Running dotnet nuget push on GPR randomly fails

Created on 29 Apr 2020  路  9Comments  路  Source: NuGet/Home

Details about Problem

Error:

Run dotnet nuget push *.nupkg --skip-duplicate --source GPR
warn : No API Key was provided and no API Key could be found for 'https://nuget.pkg.github.com/yaos'. To save an API Key for a source use the 'setApiKey' command.
Pushing yaos.OpenAPI.Diff.1.1.2-alpha.30.nupkg to 'https://nuget.pkg.github.com/yaos'...
  PUT https://nuget.pkg.github.com/yaos/
An error was encountered when fetching 'PUT https://nuget.pkg.github.com/yaos/'. The request will now be retried.
An error occurred while sending the request.
  The response ended prematurely.
  PUT https://nuget.pkg.github.com/yaos/
An error was encountered when fetching 'PUT https://nuget.pkg.github.com/yaos/'. The request will now be retried.
An error occurred while sending the request.
  The response ended prematurely.
  PUT https://nuget.pkg.github.com/yaos/
error: An error occurred while sending the request.
error:   The response ended prematurely.

dotnet --version 3.1.201
dotnet nuget --version 5.5.0.4
OS version: ubuntu-latest

Detailed repro steps so we can see the same problem

Running the following action:

name: Publish pre-release

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  publish-lib:
    runs-on: ubuntu-latest
    name: Publish OpenAPI Diff Action tool to nuget
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        with:
          fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
      - name: Setup nbgv
        uses: aarnott/[email protected]
      - name: Create the package
        run: dotnet pack --configuration Release
      - name: Add GPR Source
        run: dotnet nuget add source https://nuget.pkg.github.com/yaos/index.json --name GPR --username fabich --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text
      - name: Publish the package
        run: dotnet nuget push *.nupkg --skip-duplicate --source GPR
        working-directory: ./src/yaos.OpenAPI.Diff/nupkg

Workaround

- name: Publish the package
        run: |
          until dotnet nuget push *.nupkg --skip-duplicate --source GPR; do echo "Retrying"; sleep 1; done
        working-directory: ./src/yaos.OpenAPI.Diff/nupkg

There is a similar issue #8580 that has been closed but I don't think that the suggested workaround works.

GitHub External

Most helpful comment

Hi @fabich,

You should find the following will publish consistently:

dotnet nuget push *.nupkg --skip-duplicate --api-key ${{ github.token }} --source https://nuget.pkg.github.com/yaos

Support for the dotnet nuget push --api-key option has now been added to GitHub Packages. For some reason this works consistently, but using basic auth (password in nuget.config file) fails randomly!

All 9 comments

I have a similar issue where push to GPR seems to be randomly failing. Our authentication is defined in a nuget.config file in the root of the project repository. Our build only runs on Windows.

lang=xml <?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="github" value="https://nuget.pkg.github.com/<org>/index.json" /> </packageSources> <packageSourceCredentials> <github> <add key="Username" value="Github CI" /> <add key="ClearTextPassword" value="%GITHUB_TOKEN%" /> </github> </packageSourceCredentials> </configuration>

@zkat I'm still running into the same issue with the solution you suggested.

warn : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured. Unauthorized https://nuget.pkg.github.com/<corp>/ 451ms error: Response status code does not indicate success: 401 (Unauthorized).

my yml:

name: Publish API Clients

on:
  push:
    branches:
      - master
      - preview
      - unofficial
  watch:
    types: [started]

jobs:
  publish-csharp:
    runs-on: ubuntu-latest
    name: Publish C# Clients
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        with:
          fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
      - name: Setup .NET Core
        uses: actions/setup-dotnet@v1
        with:
          source-url: https://nuget.pkg.github.com/<corp>/index.json
        env:
          NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
      - name: Setup nbgv
        uses: aarnott/[email protected]
      - name: Create the package
        run: dotnet pack --configuration Release --output out
        working-directory: ./src/API/csharp/<pkg>
      - name: Push generated package to GitHub registry
        run: dotnet nuget push *.nupkg --skip-duplicate --no-symbols true
        working-directory: ./src/API/csharp/<pkg>/out/

my .csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <OutputType>Library</OutputType>
    <PackageId>...</PackageId>
    <Authors>...</Authors>
    <Company>...</Company>
    <Description>Cross Platform API Client for ....</Description>
    <Copyright>...</Copyright>
    <PackageTags>...</PackageTags>
    <RepositoryUrl>...</RepositoryUrl>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
  </ItemGroup>

</Project>

may I kindly ask you to reopen this issue?

@ZEisinger maybe this is something you know more about?

I am having this same problem. I spent a good chunk of yesterday afternoon trying to get my nuget package to push to GPR. I followed all the instructions and set the parameters for the setup-dotnet action task as seen in all the documentation. I finally got one successful push this morning, but the only thing I changed between success and the previous failure was adding a step to list the directory contents. (That was just an attempt on my part to make sure I was understanding the working directory correctly since github actions are new to me.)
When it fails, the error message I receive is:

An error was encountered when fetching 'PUT https://nuget.pkg.github.com/d2asolutions/'. The request will now be retried.
An error occurred while sending the request.
  The response ended prematurely.

I see this three times.
This is just a simple dotnet library package build that I'm trying to move from Azure pipelines to github actions. I've been wondering if I should try to use Azure artifacts instead of GPR to eliminate this pain point. Any suggestions as to what might be going on?

Hi @egeyer
sorry, only saw your answers just now.

GitHub Developer Support suggested using the following .net core tool:
https://github.com/jcansdale/gpr

Also see: #8580 (comment)

See my response from GitHub Enterprise Support on how they're recommending we navigate this issue!

Hi @fabich,

You should find the following will publish consistently:

dotnet nuget push *.nupkg --skip-duplicate --api-key ${{ github.token }} --source https://nuget.pkg.github.com/yaos

Support for the dotnet nuget push --api-key option has now been added to GitHub Packages. For some reason this works consistently, but using basic auth (password in nuget.config file) fails randomly!

Was this page helpful?
0 / 5 - 0 ratings