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"
@@ -35,7 +35,7 @@ Set-StrictMode -Version 2.0
35
35
. $PSScriptRoot \tools.ps1
36
36
37
37
# Add source entry to PackageSources
38
- function AddPackageSource ($sources , $SourceName , $SourceEndPoint , $creds , $Username , $Password ) {
38
+ function AddPackageSource ($sources , $SourceName , $SourceEndPoint , $creds , $Username , $pwd ) {
39
39
$packageSource = $sources.SelectSingleNode (" add[@key='$SourceName ']" )
40
40
41
41
if ($packageSource -eq $null )
@@ -48,12 +48,17 @@ function AddPackageSource($sources, $SourceName, $SourceEndPoint, $creds, $Usern
48
48
else {
49
49
Write-Host " Package source $SourceName already present."
50
50
}
51
-
52
- AddCredential - Creds $creds - Source $SourceName - Username $Username - Password $Password
51
+
52
+ AddCredential - Creds $creds - Source $SourceName - Username $Username - pwd $pwd
53
53
}
54
54
55
55
# Add a credential node for the specified source
56
- function AddCredential ($creds , $source , $username , $password ) {
56
+ function AddCredential ($creds , $source , $username , $pwd ) {
57
+ # If no cred supplied, don't do anything.
58
+ if (! $pwd ) {
59
+ return ;
60
+ }
61
+
57
62
# Looks for credential configuration for the given SourceName. Create it if none is found.
58
63
$sourceElement = $creds.SelectSingleNode ($Source )
59
64
if ($sourceElement -eq $null )
@@ -82,17 +87,18 @@ function AddCredential($creds, $source, $username, $password) {
82
87
$passwordElement.SetAttribute (" key" , " ClearTextPassword" )
83
88
$sourceElement.AppendChild ($passwordElement ) | Out-Null
84
89
}
85
- $passwordElement.SetAttribute (" value" , $Password )
90
+
91
+ $passwordElement.SetAttribute (" value" , $pwd )
86
92
}
87
93
88
- function InsertMaestroPrivateFeedCredentials ($Sources , $Creds , $Username , $Password ) {
94
+ function InsertMaestroPrivateFeedCredentials ($Sources , $Creds , $Username , $pwd ) {
89
95
$maestroPrivateSources = $Sources.SelectNodes (" add[contains(@key,'darc-int')]" )
90
96
91
97
Write-Host " Inserting credentials for $ ( $maestroPrivateSources.Count ) Maestro's private feeds."
92
98
93
99
ForEach ($PackageSource in $maestroPrivateSources ) {
94
100
Write-Host " `t Inserting credential for Maestro's feed:" $PackageSource.Key
95
- AddCredential - Creds $creds - Source $PackageSource.Key - Username $Username - Password $Password
101
+ AddCredential - Creds $creds - Source $PackageSource.Key - Username $Username - pwd $pwd
96
102
}
97
103
}
98
104
@@ -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
@@ -144,23 +148,23 @@ if ($disabledSources -ne $null) {
144
148
$userName = " dn-bot"
145
149
146
150
# Insert credential nodes for Maestro's private feeds
147
- InsertMaestroPrivateFeedCredentials - Sources $sources - Creds $creds - Username $userName - Password $Password
151
+ InsertMaestroPrivateFeedCredentials - Sources $sources - Creds $creds - Username $userName - pwd $Password
148
152
149
153
# 3.1 uses a different feed url format so it's handled differently here
150
154
$dotnet31Source = $sources.SelectSingleNode (" add[@key='dotnet3.1']" )
151
155
if ($dotnet31Source -ne $null ) {
152
- AddPackageSource - Sources $sources - SourceName " dotnet3.1-internal" - SourceEndPoint " https://pkgs.dev.azure.com/dnceng/_packaging/dotnet3.1-internal/nuget/v2" - Creds $creds - Username $userName - Password $Password
153
- 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 - Password $Password
156
+ AddPackageSource - Sources $sources - SourceName " dotnet3.1-internal" - SourceEndPoint " https://pkgs.dev.azure.com/dnceng/_packaging/dotnet3.1-internal/nuget/v2" - Creds $creds - Username $userName - pwd $Password
157
+ 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
154
158
}
155
159
156
- $dotnetVersions = @ (' 5' , ' 6' , ' 7' , ' 8' )
160
+ $dotnetVersions = @ (' 5' , ' 6' , ' 7' , ' 8' , ' 9 ' )
157
161
158
162
foreach ($dotnetVersion in $dotnetVersions ) {
159
163
$feedPrefix = " dotnet" + $dotnetVersion ;
160
164
$dotnetSource = $sources.SelectSingleNode (" add[@key='$feedPrefix ']" )
161
165
if ($dotnetSource -ne $null ) {
162
- AddPackageSource - Sources $sources - SourceName " $feedPrefix -internal" - SourceEndPoint " https://pkgs.dev.azure.com/dnceng/internal/_packaging/$feedPrefix -internal/nuget/v2" - Creds $creds - Username $userName - Password $Password
163
- AddPackageSource - Sources $sources - SourceName " $feedPrefix -internal-transport" - SourceEndPoint " https://pkgs.dev.azure.com/dnceng/internal/_packaging/$feedPrefix -internal-transport/nuget/v2" - Creds $creds - Username $userName - Password $Password
166
+ AddPackageSource - Sources $sources - SourceName " $feedPrefix -internal" - SourceEndPoint " https://pkgs.dev.azure.com/dnceng/internal/_packaging/$feedPrefix -internal/nuget/v2" - Creds $creds - Username $userName - pwd $Password
167
+ AddPackageSource - Sources $sources - SourceName " $feedPrefix -internal-transport" - SourceEndPoint " https://pkgs.dev.azure.com/dnceng/internal/_packaging/$feedPrefix -internal-transport/nuget/v2" - Creds $creds - Username $userName - pwd $Password
164
168
}
165
169
}
166
170
0 commit comments