1- # This file is a temporary workaround for internal builds to be able to restore from private AzDO feeds.
2- # This file should be removed as part of this issue: https://github.com/dotnet/arcade/issues/4080
1+ # This script adds internal feeds required to build commits that depend on internal package sources. For instance,
2+ # dotnet6-internal would be added automatically if dotnet6 was found in the nuget.config file. In addition also enables
3+ # disabled internal Maestro (darc-int*) feeds.
34#
4- # What the script does is iterate over all package sources in the pointed NuGet.config and add a credential entry
5- # under <packageSourceCredentials> for each Maestro managed private feed. Two additional credential
6- # entries are also added for the two private static internal feeds: dotnet3-internal and dotnet3-internal-transport.
5+ # Optionally, this script also adds a credential entry for each of the internal feeds if supplied.
76#
8- # This script needs to be called in every job that will restore packages and which the base repo has
9- # private AzDO feeds in the NuGet.config.
10- #
11- # See example YAML call for this script below. Note the use of the variable `$(dn-bot-dnceng-artifact-feeds-rw)`
12- # from the AzureDevOps-Artifact-Feeds-Pats variable group.
13- #
14- # Any disabledPackageSources entries which start with "darc-int" will be re-enabled as part of this script executing
7+ # See example call for this script below.
158#
169# - task: PowerShell@2
1710# displayName: Setup Private Feeds Credentials
2114# arguments: -ConfigFile $(Build.SourcesDirectory)/NuGet.config -Password $Env:Token
2215# env:
2316# Token: $(dn-bot-dnceng-artifact-feeds-rw)
17+ #
18+ # Note that the NuGetAuthenticate task should be called after SetupNugetSources.
19+ # This ensures that:
20+ # - Appropriate creds are set for the added internal feeds (if not supplied to the scrupt)
21+ # - The credential provider is installed.
22+ #
23+ # This logic is also abstracted into enable-internal-sources.yml.
2424
2525[CmdletBinding ()]
2626param (
2727 [Parameter (Mandatory = $true )][string ]$ConfigFile ,
28- [ Parameter ( Mandatory = $true )][ string ] $Password
28+ $Password
2929)
3030
3131$ErrorActionPreference = " Stop"
@@ -48,11 +48,17 @@ function AddPackageSource($sources, $SourceName, $SourceEndPoint, $creds, $Usern
4848 else {
4949 Write-Host " Package source $SourceName already present."
5050 }
51+
5152 AddCredential - Creds $creds - Source $SourceName - Username $Username - pwd $pwd
5253}
5354
5455# Add a credential node for the specified source
5556function AddCredential ($creds , $source , $username , $pwd ) {
57+ # If no cred supplied, don't do anything.
58+ if (! $pwd ) {
59+ return ;
60+ }
61+
5662 # Looks for credential configuration for the given SourceName. Create it if none is found.
5763 $sourceElement = $creds.SelectSingleNode ($Source )
5864 if ($sourceElement -eq $null )
@@ -110,11 +116,6 @@ if (!(Test-Path $ConfigFile -PathType Leaf)) {
110116 ExitWithExitCode 1
111117}
112118
113- if (! $Password ) {
114- Write-PipelineTelemetryError - Category ' Build' - Message ' Eng/common/SetupNugetSources.ps1 returned a non-zero exit code. Please supply a valid PAT'
115- ExitWithExitCode 1
116- }
117-
118119# Load NuGet.config
119120$doc = New-Object System.Xml.XmlDocument
120121$filename = (Get-Item $ConfigFile ).FullName
@@ -127,11 +128,14 @@ if ($sources -eq $null) {
127128 $doc.DocumentElement.AppendChild ($sources ) | Out-Null
128129}
129130
130- # Looks for a <PackageSourceCredentials> node. Create it if none is found.
131- $creds = $doc.DocumentElement.SelectSingleNode (" packageSourceCredentials" )
132- if ($creds -eq $null ) {
133- $creds = $doc.CreateElement (" packageSourceCredentials" )
134- $doc.DocumentElement.AppendChild ($creds ) | Out-Null
131+ $creds = $null
132+ if ($Password ) {
133+ # Looks for a <PackageSourceCredentials> node. Create it if none is found.
134+ $creds = $doc.DocumentElement.SelectSingleNode (" packageSourceCredentials" )
135+ if ($creds -eq $null ) {
136+ $creds = $doc.CreateElement (" packageSourceCredentials" )
137+ $doc.DocumentElement.AppendChild ($creds ) | Out-Null
138+ }
135139}
136140
137141# Check for disabledPackageSources; we'll enable any darc-int ones we find there
@@ -153,7 +157,7 @@ if ($dotnet31Source -ne $null) {
153157 AddPackageSource - Sources $sources - SourceName " dotnet3.1-internal-transport" - SourceEndPoint " https://pkgs.dev.azure.com/dnceng/_packaging/dotnet3.1-internal-transport/nuget/v2" - Creds $creds - Username $userName - pwd $Password
154158}
155159
156- $dotnetVersions = @ (' 5' , ' 6' , ' 7' , ' 8' )
160+ $dotnetVersions = @ (' 5' , ' 6' , ' 7' , ' 8' , ' 9 ' )
157161
158162foreach ($dotnetVersion in $dotnetVersions ) {
159163 $feedPrefix = " dotnet" + $dotnetVersion ;
@@ -164,4 +168,4 @@ foreach ($dotnetVersion in $dotnetVersions) {
164168 }
165169}
166170
167- $doc.Save ($filename )
171+ $doc.Save ($filename )
0 commit comments