76 lines
2.4 KiB
PowerShell
76 lines
2.4 KiB
PowerShell
|
function Publish-ChocoPackage {
|
|||
|
<#
|
|||
|
.SYNOPSIS
|
|||
|
Promotes a Chocolatey package from one feed to another.
|
|||
|
WARNING: Even if a package of the correct version has already been promoted to the destination feed, a fresh Promotion will occur.
|
|||
|
|
|||
|
.PARAMETER PackageName
|
|||
|
Name of the package to Promote
|
|||
|
|
|||
|
.PARAMETER Version
|
|||
|
Version of package to Promote
|
|||
|
|
|||
|
.PARAMETER ApiKey
|
|||
|
API Key for Nuget Server
|
|||
|
|
|||
|
.PARAMETER Comments
|
|||
|
Comments to post to the promotion
|
|||
|
|
|||
|
.PARAMETER FromFeed
|
|||
|
Source feed FROM which to promote PackageName
|
|||
|
|
|||
|
.PARAMETER ToFeed
|
|||
|
Destination feed TO which to promote PackageName
|
|||
|
#>
|
|||
|
[CmdletBinding()]
|
|||
|
Param(
|
|||
|
[Parameter(Mandatory = $true)]
|
|||
|
[string]$PackageName,
|
|||
|
[Parameter(Mandatory = $true)]
|
|||
|
[string]$Version,
|
|||
|
[Parameter(Mandatory = $true)]
|
|||
|
[string]$ApiKey,
|
|||
|
[Parameter(Mandatory = $true)]
|
|||
|
[string]$Comments,
|
|||
|
[Parameter(Mandatory = $false)]
|
|||
|
[string]$FromFeed = "choco.Staging",
|
|||
|
[Parameter(Mandatory = $false)]
|
|||
|
[string]$ToFeed = "choco.Prod"
|
|||
|
)
|
|||
|
$logLead = (Get-logLeadName)
|
|||
|
|
|||
|
$baseUrl = "https://packagerepo.orb.alkamitech.com";
|
|||
|
|
|||
|
$promoteUrl = "$baseUrl/api/promotions/promote?key=$ApiKey"
|
|||
|
|
|||
|
$body = @{
|
|||
|
"packageName" = $PackageName
|
|||
|
"groupName" = ""
|
|||
|
"version" = $Version
|
|||
|
"fromFeed" = $FromFeed
|
|||
|
"toFeed" = $ToFeed
|
|||
|
"comments" = $Comments
|
|||
|
}
|
|||
|
|
|||
|
try {
|
|||
|
$response = Invoke-WebRequest $promoteUrl -Body $body -Method "POST"
|
|||
|
|
|||
|
$responseContent = [System.IO.StreamReader]::new($response.RawContentStream).ReadToEnd()
|
|||
|
|
|||
|
#Proget returns an HTML page for blocked IPs. Hacky special case to handle it and potentially any others...
|
|||
|
if ($response.StatusCode -eq 200 -and $responseContent.StartsWith("<!DOCTYPE html>")) {
|
|||
|
throw $responseContent
|
|||
|
}
|
|||
|
} catch {
|
|||
|
# NOTE: Suppressing this exception means the catch in TDC's PromotePackages.ps1 has NOTHING
|
|||
|
# to catch, and therefore, never outputs the intended warning
|
|||
|
# This is ONLY called from the VerifyPackagesInFeed dependency from the PromotePackages.ps1
|
|||
|
# Allowing this to rethrow will allow that to catch and add a buildProblem
|
|||
|
$thrownException = $_
|
|||
|
Write-Warning ("$logLead : ProGet Returned Error: $thrownException")
|
|||
|
throw $thrownException
|
|||
|
}
|
|||
|
|
|||
|
Write-Host ("$logLead : Promotion complete. Proget response: $responseContent")
|
|||
|
}
|