Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
parameters:
- name: dryRun
type: boolean
default: true

- name: internalFeedSource
type: string
Expand All @@ -16,31 +17,8 @@ parameters:

steps:
- script: |
set -e
SRC='${{ parameters.internalFeedSource }}'
if [ -z "$SRC" ]; then
echo "Internal feed source parameter not set."
exit 1
fi
if [ "${{ parameters.dryRun }}" = "true" ]; then
echo "[DRY RUN] Listing packages targeted for push to: ${{ parameters.publicNuGetSource }}"
echo "Using glob pattern: ${{ parameters.packagesGlob }}"
# Derive directory and filename pattern from the glob for a precise find (handles nested patterns minimally)
glob='${{ parameters.packagesGlob }}'
dir="${glob%/*}"
name="${glob##*/}"
echo "Resolved directory: $dir"
echo "Filename pattern: $name"
if [ -d "$dir" ]; then
echo "Matched files:" || true
# Print all matched files to identify what would be pushed
find "$dir" -type f -name "$name" -print || true
else
echo "Directory does not exist yet: $dir"
fi
fi
for f in $(find "${{ parameters.packagesGlob }}" -name "*.nupkg"); do
echo "Push $f"
dotnet nuget push --source "$SRC" --api-key az "$f"
done
pwsh ./tools/scripts/publishPackagesToFeed.ps1 `
-dryRun ${{ parameters.dryRun }} `
-internalFeedSource '${{ parameters.internalFeedSource }}' `
-packagesGlob '${{ parameters.packagesGlob }}'
displayName: 'Publish to Internal Feed'
3 changes: 1 addition & 2 deletions tools/scripts/downloadLatestNuget.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# The .NET Foundation licenses this file to you under the MIT license.
# See the LICENSE file in the project root for more information.
# Script: downloadLatestNuget.ps1
# Author: Keerat Singh
# Date: 07-Dec-2018
# Comments: This script downloads the latest NuGet Binary.
#
Expand All @@ -24,4 +23,4 @@ Function DownloadLatestNuget()
Write-Output "Destination: $nugetDestPath"
Start-BitsTransfer -Source $nugetSrcPath -Destination $nugetDestPath\nuget.exe
}
DownloadLatestNuget
DownloadLatestNuget
81 changes: 81 additions & 0 deletions tools/scripts/publishPackagesToFeed.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Licensed to the .NET Foundation under one or more agreements.
# The .NET Foundation licenses this file to you under the MIT license.
# See the LICENSE file in the project root for more information.

# Script: publishPackagesToFeed.ps1
# Date: 10-12-2025
# Comments: This script publishes packages to an internal Azure DevOps Feed.

param(
[bool]$dryRun = $true,
[string]$internalFeedSource,
[string]$packagesGlob = "artifacts/packages/**/*.nupkg"
)

Function PublishToInternalFeed() {
$SRC = $internalFeedSource

if ([string]::IsNullOrEmpty($SRC)) {
Write-Host "Internal feed source parameter not set." -ForegroundColor Red
exit 1
}

Write-Host "[DRY RUN] Listing packages targeted for push to: $internalFeedSource" -ForegroundColor Cyan
Write-Host "Using glob pattern: $packagesGlob" -ForegroundColor Cyan

# Parse the glob pattern to extract directory and filename pattern
$glob = $packagesGlob
$lastSlashIndex = $glob.LastIndexOf('/')

if ($lastSlashIndex -ge 0) {
$dir = $glob.Substring(0, $lastSlashIndex)
$namePattern = $glob.Substring($lastSlashIndex + 1)
} else {
$dir = "."
$namePattern = $glob
}

# Handle ** wildcard for recursive search
$recurse = $dir -like '*/**'
if ($recurse) {
$dir = $dir -replace '/?\*\*/?', ''
}

Write-Host "Resolved directory: $dir" -ForegroundColor Yellow
Write-Host "Filename pattern: $namePattern" -ForegroundColor Yellow

if (Test-Path $dir -PathType Container) {
Write-Host "Matched files:" -ForegroundColor Green

# Find matching .nupkg files
$packages = Get-ChildItem -Path $dir -Filter "*.nupkg" -Recurse:$recurse -File -ErrorAction SilentlyContinue

if ($packages) {
foreach ($package in $packages) {
Write-Host " - $($package.FullName)" -ForegroundColor Gray
}

if (-not $dryRun) {
Write-Host "`nPushing packages to feed..." -ForegroundColor Cyan
foreach ($package in $packages) {
Write-Host "Pushing package: $($package.FullName)" -ForegroundColor Yellow
dotnet nuget push $package.FullName --source $SRC --api-key az

if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to push package: $($package.FullName)" -ForegroundColor Red
} else {
Write-Host "Successfully pushed: $($package.Name)" -ForegroundColor Green
}
}
} else {
Write-Host "`n[DRY RUN] No packages were pushed. Set -dryRun `$false to push." -ForegroundColor Yellow
}
} else {
Write-Host "No .nupkg files found matching the pattern." -ForegroundColor Yellow
}
} else {
Write-Host "Directory does not exist: $dir" -ForegroundColor Red
}
}

PublishToInternalFeed
Loading