Pushing nuget package from jenkins fails but works from the command line

I have the oddest issue ever. In my jenkins build process i run a powershell script at the end to push all my nuget packages to my octopus server. Here is the script:-

$nugets = get-childitem . -include afi*.nupkg -recurse -exclude packages | where {$.FullName -match “^.\bin\.$”}
$nugets | foreach-object -process {
try{
$command = ‘Build\NuGet.exe push "’ + $
.FullName + ‘" -ApiKey ******* -Source http://myserver.corp/nuget/packages -verbosity detailed’;
iex $command;
}catch{}
}

the output from jenkins console shows this:-

Pushing Afi.Client 1.4.0.3885 to ‘http://myserver.corp/nuget/packages’…
PUT http://myserver.corp/nuget/packages/
System.InvalidOperationException: Failed to process request. ‘Not Found’.
The remote server returned an error: (404) Not Found… —> System.Net.WebException: The remote server returned an error: (404) Not Found.
at System.Net.HttpWebRequest.GetResponse()
at NuGet.RequestHelper.GetResponse()
at NuGet.HttpClient.GetResponse()
at NuGet.PackageServer.EnsureSuccessfulResponse(HttpClient client, Nullable1 expectedStatusCode) --- End of inner exception stack trace --- at NuGet.PackageServer.EnsureSuccessfulResponse(HttpClient client, Nullable1 expectedStatusCode)
at NuGet.PackageServer.PushPackageToServer(String apiKey, Func`1 packageStreamFactory, Int64 packageSize, Int32 timeout, Boolean disableBuffering)
at NuGet.PackageServer.PushPackage(String apiKey, IPackage package, Int64 packageSize, Int32 timeout, Boolean disableBuffering)
at NuGet.Commands.PushCommand.PushPackageCore(String source, String apiKey, PackageServer packageServer, String packageToPush, TimeSpan timeout)
at NuGet.Commands.PushCommand.PushPackage(String packagePath, String source, String apiKey, TimeSpan timeout)
at NuGet.Commands.PushCommand.ExecuteCommand()
at NuGet.Commands.Command.Execute()
at NuGet.Program.Main(String[] args)

and now for the odd part. If i run this exact same script from the console via a “powershell script.ps1” command it works. The library in octopus is updated with my new packages.

Any ideas?

Ta

Cedric

Hi Cedric,

Thanks for getting in touch! Due to the fact that this is running on your command line but not in Jenkins leads us to two possibilities. Either it’s to do with permissions under the user that Jenkins is running vs the permissions when you run from command line or a proxy server in the way.
To test either you could download and run Fiddler and do the commands manually, then again in Jenkins and see if you can see any differences.

Let me know what you find.
Vanessa

Hi Vanessa,

Well the stupid award goes to me! It suddenly occurred on me that I set the http_proxy variable in the environment so that when I build the solution nugget can download the packages. If I add the “Remove-Item env:\http_proxy;” line before my foreach then all is well.

New question now…
How to push a package and overwrite it if it’s already in the repository?

image001.jpg

Hi Cedric,

There is no way to force an overwrite of the package in this form.

Vanessa