Skip to content

Commit f38655c

Browse files
Merge pull request #287 from chocolatey/clientJenkinsFixes
Fixes Jenkins Pushing and ClientSetup
2 parents 3caae82 + 5ff550c commit f38655c

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
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

scripts/ClientSetup.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ if ($Credential) {
8484

8585
# Find the latest version of Chocolatey, if a version was not specified
8686
$NupkgUrl = if (-not $ChocolateyVersion) {
87-
$QueryUrl = ($RepositoryUrl.TrimEnd('/index.json'), "v3/registration/Chocolatey/index.json") -join '/'
87+
$QueryUrl = (($RepositoryUrl -replace '/index\.json$'), "v3/registration/Chocolatey/index.json") -join '/'
8888
$Result = $webClient.DownloadString($QueryUrl) | ConvertFrom-Json
8989
$Result.items.items[-1].packageContent
9090
} else {
9191
# Otherwise, assume the URL
92-
"$($RepositoryUrl.TrimEnd('/index.json'))/v3/content/chocolatey/$($ChocolateyVersion)/chocolatey.$($ChocolateyVersion).nupkg"
92+
"$($RepositoryUrl -replace '/index\.json$')/v3/content/chocolatey/$($ChocolateyVersion)/chocolatey.$($ChocolateyVersion).nupkg"
9393
}
9494

9595
# Download the NUPKG

0 commit comments

Comments
 (0)