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.
3
4
#
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.
7
6
#
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.
15
8
#
16
9
# - task: PowerShell@2
17
10
# displayName: Setup Private Feeds Credentials
21
14
# arguments: -ConfigFile $(Build.SourcesDirectory)/NuGet.config -Password $Env:Token
22
15
# env:
23
16
# 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.
24
24
25
25
[CmdletBinding ()]
26
26
param (
27
27
[Parameter (Mandatory = $true )][string ]$ConfigFile ,
28
- [ Parameter ( Mandatory = $true )][ string ] $Password
28
+ $Password
29
29
)
30
30
31
31
$ErrorActionPreference = " Stop"
@@ -48,11 +48,17 @@ function AddPackageSource($sources, $SourceName, $SourceEndPoint, $creds, $Usern
48
48
else {
49
49
Write-Host " Package source $SourceName already present."
50
50
}
51
+
51
52
AddCredential - Creds $creds - Source $SourceName - Username $Username - pwd $pwd
52
53
}
53
54
54
55
# Add a credential node for the specified source
55
56
function AddCredential ($creds , $source , $username , $pwd ) {
57
+ # If no cred supplied, don't do anything.
58
+ if (! $pwd ) {
59
+ return ;
60
+ }
61
+
56
62
# Looks for credential configuration for the given SourceName. Create it if none is found.
57
63
$sourceElement = $creds.SelectSingleNode ($Source )
58
64
if ($sourceElement -eq $null )
@@ -110,11 +116,6 @@ if (!(Test-Path $ConfigFile -PathType Leaf)) {
110
116
ExitWithExitCode 1
111
117
}
112
118
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
-
118
119
# Load NuGet.config
119
120
$doc = New-Object System.Xml.XmlDocument
120
121
$filename = (Get-Item $ConfigFile ).FullName
@@ -127,11 +128,14 @@ if ($sources -eq $null) {
127
128
$doc.DocumentElement.AppendChild ($sources ) | Out-Null
128
129
}
129
130
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
+ }
135
139
}
136
140
137
141
# Check for disabledPackageSources; we'll enable any darc-int ones we find there
@@ -164,4 +168,4 @@ foreach ($dotnetVersion in $dotnetVersions) {
164
168
}
165
169
}
166
170
167
- $doc.Save ($filename )
171
+ $doc.Save ($filename )
0 commit comments