Skip to content

Commit 15db143

Browse files
Merge pull request #288 from chocolatey/fixJenkins
(fix) Enable Sources before Pushing
2 parents f38655c + c7f973b commit 15db143

File tree

4 files changed

+67
-22
lines changed

4 files changed

+67
-22
lines changed

jenkins/Internalize packages from the Community Repository/config.xml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,28 @@
3131
powershell '''
3232
$temp = Join-Path -Path $env:TEMP -ChildPath ([GUID]::NewGuid()).Guid
3333
$null = New-Item -Path $temp -ItemType Directory
34+
$LocalRepoSource = $(choco source --limit-output | ConvertFrom-Csv -Delimiter '|' -Header Name, Uri, Disabled).Where{
35+
$_.Uri -eq $env:P_DST_URL
36+
}[0]
37+
3438
Write-Output "Created temporary directory '$temp'."
3539
($env:P_PKG_LIST).split(';,') | ForEach-Object {
3640
choco download $_ --no-progress --internalize --force --internalize-all-urls --append-use-original-location --output-directory=$temp --source='https://community.chocolatey.org/api/v2/'
3741
if ($LASTEXITCODE -eq 0) {
38-
(Get-Item -Path (Join-Path -Path $temp -ChildPath "*.nupkg")).fullname | ForEach-Object {
39-
choco push $_ --source "$($env:P_DST_URL)" --api-key "$($env:P_API_KEY)" --force
40-
if ($LASTEXITCODE -eq 0) {
41-
Write-Verbose "Package '$_' pushed to '$($env:P_DST_URL)'.";
42-
}
43-
else {
44-
Write-Verbose "Package '$_' could not be pushed to '$($env:P_DST_URL)'.`nThis could be because it already exists in the repository at a higher version and can be mostly ignored. Check error logs."
45-
}
46-
}
42+
try {
43+
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source enable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
44+
(Get-Item -Path (Join-Path -Path $temp -ChildPath "*.nupkg")).fullname | ForEach-Object {
45+
choco push $_ --source "$($env:P_DST_URL)" --api-key "$($env:P_API_KEY)" --force
46+
if ($LASTEXITCODE -eq 0) {
47+
Write-Verbose "Package '$_' pushed to '$($env:P_DST_URL)'.";
48+
}
49+
else {
50+
Write-Verbose "Package '$_' could not be pushed to '$($env:P_DST_URL)'.`nThis could be because it already exists in the repository at a higher version and can be mostly ignored. Check error logs."
51+
}
52+
}
53+
} finally {
54+
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source disable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
55+
}
4756
}
4857
else {
4958
Write-Output "Failed to download package '$_'"

jenkins/scripts/Get-UpdatedPackage.ps1

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ if (([version] (choco --version).Split('-')[0]) -ge [version] '2.1.0') {
2020
choco cache remove
2121
}
2222

23+
$LocalRepoSource = $(choco source --limit-output | ConvertFrom-Csv -Delimiter '|' -Header Name, Uri, Disabled).Where{
24+
$_.Uri -eq $LocalRepo -or
25+
$_.Name -eq $LocalRepo
26+
}[0]
27+
2328
Write-Verbose "Getting list of local packages from '$LocalRepo'."
2429
$localPkgs = choco search --source $LocalRepo -r | ConvertTo-ChocoObject
2530
Write-Verbose "Retrieved list of $(($localPkgs).count) packages from '$Localrepo'."
@@ -34,15 +39,21 @@ $localPkgs | ForEach-Object {
3439
choco download $_.name --no-progress --internalize --force --internalize-all-urls --append-use-original-location --output-directory=$tempPath --source=$RemoteRepo
3540

3641
if ($LASTEXITCODE -eq 0) {
37-
Write-Verbose "Pushing package '$($_.name)' to local repository '$LocalRepo'."
38-
(Get-Item -Path (Join-Path -Path $tempPath -ChildPath "*.nupkg")).fullname | ForEach-Object {
39-
choco push $_ --source $LocalRepo --api-key $LocalRepoApiKey --force
40-
if ($LASTEXITCODE -eq 0) {
41-
Write-Verbose "Package '$_' pushed to '$LocalRepo'."
42-
}
43-
else {
44-
Write-Verbose "Package '$_' could not be pushed to '$LocalRepo'.`nThis could be because it already exists in the repository at a higher version and can be mostly ignored. Check error logs."
42+
try {
43+
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source enable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
44+
45+
Write-Verbose "Pushing package '$($_.name)' to local repository '$LocalRepo'."
46+
(Get-Item -Path (Join-Path -Path $tempPath -ChildPath "*.nupkg")).fullname | ForEach-Object {
47+
choco push $_ --source $LocalRepo --api-key $LocalRepoApiKey --force
48+
if ($LASTEXITCODE -eq 0) {
49+
Write-Verbose "Package '$_' pushed to '$LocalRepo'."
50+
}
51+
else {
52+
Write-Verbose "Package '$_' could not be pushed to '$LocalRepo'.`nThis could be because it already exists in the repository at a higher version and can be mostly ignored. Check error logs."
53+
}
4554
}
55+
} finally {
56+
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source disable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
4657
}
4758
}
4859
else {

jenkins/scripts/Invoke-ChocolateyInternalizer.ps1

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,23 @@ begin {
4343
Join-Path -ChildPath $Guid |
4444
New-Item -ItemType Directory -Path { $_ } |
4545
Select-Object -ExpandProperty FullName
46+
47+
$LocalRepoSource = $(choco source --limit-output | ConvertFrom-Csv -Delimiter '|' -Header Name, Uri, Disabled).Where{
48+
$_.Uri -eq $RepositoryUrl
49+
}[0]
4650
}
4751
process {
4852
foreach ($item in $Package) {
4953
choco download $item --internalize --output-directory="'$TempFolder'" --no-progress --internalize-all-urls --append-use-original-location --source="'$RemoteRepo'"
50-
Get-ChildItem -Path $TempFolder -Filter *.nupkg -Recurse -File | ForEach-Object {
51-
choco push $_.Fullname --source="'$RepositoryUrl'" --api-key="'$NexusApiKey'" --force
52-
Remove-Item -Path $_.FullName -Force
54+
try {
55+
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source enable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
56+
57+
Get-ChildItem -Path $TempFolder -Filter *.nupkg -Recurse -File | ForEach-Object {
58+
choco push $_.Fullname --source="'$RepositoryUrl'" --api-key="'$NexusApiKey'" --force
59+
Remove-Item -Path $_.FullName -Force
60+
}
61+
} finally {
62+
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source disable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
5363
}
5464
}
5565
}

jenkins/scripts/Update-ProdRepoFromTest.ps1

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,18 @@ if (([version] (choco --version).Split('-')[0]) -ge [version] '2.1.0') {
1818
choco cache remove
1919
}
2020

21+
$LocalRepoSource = $(choco source --limit-output | ConvertFrom-Csv -Delimiter '|' -Header Name, Uri, Disabled).Where{
22+
$_.Uri -eq $TestRepo -or
23+
$_.Name -eq $TestRepo
24+
}[0]
25+
2126
Write-Verbose "Checking the list of packages available in the test and prod repositories"
22-
$testPkgs = choco search --source $TestRepo --all-versions --limit-output | ConvertFrom-Csv -Delimiter '|' -Header Name, Version
27+
try {
28+
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source enable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
29+
$testPkgs = choco search --source $TestRepo --all-versions --limit-output | ConvertFrom-Csv -Delimiter '|' -Header Name, Version
30+
} finally {
31+
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source disable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
32+
}
2333
$prodPkgs = choco search --source $ProdRepo --all-versions --limit-output | ConvertFrom-Csv -Delimiter '|' -Header Name, Version
2434
$tempPath = Join-Path -Path $env:TEMP -ChildPath ([GUID]::NewGuid()).GUID
2535

@@ -35,7 +45,12 @@ else {
3545

3646
$Packages | ForEach-Object {
3747
Write-Verbose "Downloading package '$($_.Name)' v$($_.Version) to '$tempPath'."
38-
choco download $_.Name --version $_.Version --no-progress --output-directory=$tempPath --source=$TestRepo --ignore-dependencies
48+
try {
49+
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source enable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
50+
choco download $_.Name --version $_.Version --no-progress --output-directory=$tempPath --source=$TestRepo --ignore-dependencies
51+
} finally {
52+
if ([bool]::Parse($LocalRepoSource.Disabled)) {choco source disable --name="$($LocalRepoSource.Name)" -r | Write-Verbose}
53+
}
3954

4055
if ($LASTEXITCODE -eq 0) {
4156
$pkgPath = (Get-Item -Path (Join-Path -Path $tempPath -ChildPath '*.nupkg')).FullName

0 commit comments

Comments
 (0)