Publish a package to a nuget feed

Share your PowerShell scripts for Deployment Manager

Moderators: Mike Upton, justin.caldicott, csmith, chirayu, DavidSimner

Publish a package to a nuget feed

Postby PeterG » Tue Aug 20, 2013 10:55 am

A script for publishing a nuget package to a feed:

Code: Select all
# Input:
# Required
# $nugetServer = http://localhost:8080/nuget/
# $nugetPackagePath = C:\\foo.nukpg
#
# Optional
# $nugetAPIKey = 4003d786-cc37-4004-bfdf-c4f3e8ef9b3a

# For more information visit:
# http://docs.nuget.org/docs/reference/command-line-reference#Push_Command

# Requires nuget to be setup on agent



# Check if nuget is available
try {
# An error is thrown if nuget doesn't exist,
# but it's not terminating, which is not the behaviour we want
# so stop on all errors
   $temp = $ErrorActionPreference
   $ErrorActionPreference = "Stop"
   $nuget = Get-Command "nuget.exe"
   $ErrorActionPreference = $temp
} catch {
   throw "NuGet is unavailable"
}

$errors = ""
if ($null -eq $nugetServer) {
   $errors = $errors + ", nugetServer"
}
if ($null -eq $nugetPackagePath) {
   $errors = $errors + ", nugetPackagePath"
}

if (0 -ne $errors.length) {
   # Throw an error and stop deployment from continuing further
   throw ($errors.trim(", ") + " must be set to push a package")
}

nuget push -Source $nugetServer $nugetPackagePath $nugetAPIKey | Out-Default
Peter Gerrard
Intern - Deployment Manager
PeterG
 
Posts: 4
Joined: Tue Aug 20, 2013 10:40 am

Return to Deployment Manager PowerShell Scripts

Who is online

Users browsing this forum: No registered users and 0 guests