functions/Push-ChocoIntPackage.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<#
.SYNOPSIS
    Short description
.DESCRIPTION
    Long description
.EXAMPLE
PS C:\Chocotemp> $Upgradepkgs = Invoke-ChocoUpgradeIntPackage -PackageNames $intpkgs -Path $Path |
 Where-Object {$_.Result -eq 'Upgrade Success'}
 
PS C:\Chocotemp> Push-ChocoIntPackage -PackageNames $Upgradepkgs -Path $Path `
-ApiKey $Api -RepositoryURL $LocalRepo |
Where-Object {$_.Result -like 'Push Success'}
 
Name Result Version NuGetPackage
---- ------ ------- ------------
curl Push Success 7.64.1 C:\Chocotemp\curl.7.64.1.nupkg
chocolatey-core.extension Push Success 1.3.3 C:\Chocotemp\chocolatey-core.extension.1.3.3.nupkgpkg
GoogleChrome Push Success 74.0.3729.131 C:\Chocotemp\GoogleChrome.74.0.3729.131.nupkg
 
#>

function Push-ChocoIntPackage {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipeline=$True)]
        [pscustomobject[]]$PackageNames,
        [Parameter(Mandatory=$true)]
        [string]$Path,
        [Parameter(Mandatory=$true)]
        [string]$RepositoryURL,
        [Parameter(Mandatory=$true)]
        [ValidateNotNull()]
        [System.Management.Automation.PSCredential]$ApiKey
    )
    process {
        foreach ($Package in $PackageNames){
            foreach ($NuPkg in $Package.NuGetpkgs) {
                $MetaData = Get-ChocoPackageMetaData -ChocolateyPackage $NuPkg
                choco push $NuPkg --force --source $RepositoryURL --api-key $ApiKey.GetNetworkCredential().Password --timeout=3600 | Write-Verbose
                if ($LASTEXITCODE -ne 0){
                   $Result = 'Push Failed'
                }
                else {
                    $Result = 'Push Success'
                }
                    Write-Verbose "$($MetaData.Name) push failed"
                    [PSCustomObject]@{
                        Name = $MetaData.Name
                        Result = $Result
                        Version = $MetaData.Version
                        NuGetPackage = $NuPkg
                        }
                }
            }
        }
    }