Skip to content

Commit 5ff550c

Browse files
committed
(#286) Set Explicit Source for Each Repository
Updates to Chocolatey CLI mean that we can not rely on implicit credentials for a source. This change ensures credentials for each potential source are added to the machine, for Jenkins to use.
1 parent 75da0b0 commit 5ff550c

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

Set-SslSecurity.ps1

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ process {
120120
Write-Host "Nexus is ready!"
121121

122122
Invoke-Choco source remove --name="'ChocolateyInternal'"
123-
$RepositoryUrl = "https://${SubjectWithoutCn}:8443/repository/ChocolateyInternal/index.json"
124123

125124
# Build Credential Object, Connect to Nexus
126125
$securePw = (Get-Content 'C:\programdata\sonatype-work\nexus3\admin.password') | ConvertTo-SecureString -AsPlainText -Force
@@ -156,34 +155,39 @@ process {
156155
Password = ($NexusPw | ConvertTo-SecureString -AsPlainText -Force)
157156
FirstName = 'Choco'
158157
LastName = 'User'
159-
EmailAddress = 'chocouser@foo.com'
158+
EmailAddress = 'chocouser@example.com'
160159
Status = 'Active'
161160
Roles = 'chocorole'
162161
}
163162
New-NexusUser @UserParams
164163
}
165164

166-
$ChocoArgs = @(
167-
'source',
168-
'add',
169-
"--name='ChocolateyInternal'",
170-
"--source='$RepositoryUrl'",
171-
'--priority=1',
172-
"--user='chocouser'",
173-
"--password='$NexusPw'"
174-
)
175-
& Invoke-Choco @ChocoArgs
176-
177-
# Update Repository API key
178-
$chocoArgs = @('apikey', "--source='$RepositoryUrl'", "--api-key='$NuGetApiKey'")
179-
& Invoke-Choco @chocoArgs
180-
181-
# Reset the NuGet v3 cache, such that it doesn't capture localhost as the FQDN
182-
Remove-NexusRepositoryFolder -RepositoryName ChocolateyInternal -Name v3
165+
# Update all sources with credentials and the new path
166+
foreach ($Repository in Get-NexusRepository -Format nuget | Where-Object Type -eq 'hosted') {
167+
$RepositoryUrl = "https://${SubjectWithoutCn}:8443/repository/$($Repository.Name)/index.json"
168+
169+
$ChocoArgs = @(
170+
'source',
171+
'add',
172+
"--name='$($Repository.Name)'",
173+
"--source='$RepositoryUrl'",
174+
'--priority=1',
175+
"--user='chocouser'",
176+
"--password='$NexusPw'"
177+
)
178+
& Invoke-Choco @ChocoArgs
179+
180+
# Update Repository API key
181+
$chocoArgs = @('apikey', "--source='$RepositoryUrl'", "--api-key='$NuGetApiKey'")
182+
& Invoke-Choco @chocoArgs
183+
184+
# Reset the NuGet v3 cache, such that it doesn't capture localhost as the FQDN
185+
Remove-NexusRepositoryFolder -RepositoryName $Repository.Name -Name v3
186+
}
183187

184188
Update-Clixml -Properties @{
185189
NexusUri = "https://$($SubjectWithoutCn):8443"
186-
NexusRepo = $RepositoryUrl
190+
NexusRepo = "https://${SubjectWithoutCn}:8443/repository/ChocolateyInternal/index.json"
187191
ChocoUserPassword = $NexusPw
188192
}
189193

Start-C4bNexusSetup.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ process {
8484
# Add ChocolateyInternal as a source repository
8585
Invoke-Choco source add -n 'ChocolateyInternal' -s "$((Get-NexusRepository -Name 'ChocolateyInternal').url)/index.json" --priority 1
8686

87-
#Remove Local Chocolatey Setup Source
87+
# Add ChocolateyTest as a source repository, to enable authenticated pushing
88+
Invoke-Choco source add -n 'ChocolateyTest' -s "$((Get-NexusRepository -Name 'ChocolateyTest').url)/index.json"
89+
Invoke-Choco source disable -n 'ChocolateyTest'
90+
91+
# Remove Local Chocolatey Setup Source
8892
$chocoArgs = @('source', 'remove', '--name="LocalChocolateySetup"')
8993
& Invoke-Choco @chocoArgs
9094

0 commit comments

Comments
 (0)