Skip to content

Commit aaf6e64

Browse files
committed
(chocolatey#193) Remove Jenkins Initial Setup Menus
Signed-off-by: Ryan Richter <[email protected]>
1 parent 03d1d6d commit aaf6e64

File tree

5 files changed

+171
-70
lines changed

5 files changed

+171
-70
lines changed

Start-C4bJenkinsSetup.ps1

Lines changed: 131 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ param(
1919
)
2020

2121
begin {
22-
if($host.name -ne 'ConsoleHost') {
22+
if ($host.name -ne 'ConsoleHost') {
2323
Write-Warning "This script cannot be ran from within PowerShell ISE"
2424
Write-Warning "Please launch powershell.exe as an administrator, and run this script again"
2525
break
@@ -39,13 +39,56 @@ process {
3939
$chocoArgs = @('install', 'temurin11jre', '-y', "--source='$Source'", '--no-progress')
4040
& choco @chocoArgs
4141

42+
# Enviornment variable used to disbale jenkins instal login prompts
43+
[Environment]::SetEnvironmentVariable('JAVA_OPTS', '-Djenkins.install.runSetupWizard=false', 'Machine')
44+
4245
# Install Jenkins
43-
$chocoArgs = @('install', 'jenkins', '-y', "--source='$Source'", '--no-progress')
46+
$chocoArgs = @('install', 'jenkins', '--version=2.401.2', '-y', "--source='$Source'", '--no-progress')
4447
& choco @chocoArgs
4548

4649
Write-Host "Giving Jenkins 30 seconds to complete background setup..." -ForegroundColor Green
4750
Start-Sleep -Seconds 30 # Jenkins needs a moment
4851

52+
# Disabling inital setup prompts
53+
$JenkinsHome = "C:\ProgramData\Jenkins\.jenkins"
54+
55+
$JenkinsVersion = (choco list jenkins --exact --limit-output).Split('|')[1]
56+
$JenkinsVersion | Out-File -FilePath $JenkinsHome\jenkins.install.UpgradeWizard.state -Encoding utf8
57+
$JenkinsVersion | Out-File -FilePath $JenkinsHome\jenkins.install.InstallUtil.lastExecVersion -Encoding utf8
58+
59+
# Set the external hostname, such that it's ready for use. This may change, but we've pinned Jenkin's version.
60+
@"
61+
<?xml version='1.1' encoding='UTF-8'?>
62+
<jenkins.model.JenkinsLocationConfiguration>
63+
<adminAddress>address not configured yet &lt;nobody@nowhere&gt;</adminAddress>
64+
<jenkinsUrl>http://$($HostName):8080</jenkinsUrl>
65+
</jenkins.model.JenkinsLocationConfiguration>
66+
"@ | Out-File -FilePath $JenkinsHome\jenkins.model.JenkinsLocationConfiguration.xml -Encoding utf8
67+
68+
#region BCrypt Password
69+
if (-not (Test-Path "$PSScriptRoot\bcrypt.net.0.1.0\lib\net35\BCrypt.Net.dll")) {
70+
$BCryptNugetUri = 'https://www.nuget.org/api/v2/package/BCrypt.Net/0.1.0'
71+
$ZipPath = "$PSScriptRoot\bcrypt.net.0.1.0.zip"
72+
73+
Invoke-WebRequest -Uri $BCryptNugetUri -OutFile $ZipPath -UseBasicParsing
74+
Expand-Archive -Path $ZipPath
75+
}
76+
77+
Add-Type -Path "$PSScriptRoot\bcrypt.net.0.1.0\lib\net35\BCrypt.Net.dll"
78+
$Salt = [bcrypt.net.bcrypt]::generatesalt(15)
79+
80+
$JenkinsCred = [System.Net.NetworkCredential]::new(
81+
"admin",
82+
(New-ServicePassword -Length 32)
83+
)
84+
85+
$AdminUserPath = Resolve-Path "$JenkinsHome\users\admin_*\config.xml"
86+
# Can't load as XML document as file is XML v1.1
87+
(Get-Content $AdminUserPath) -replace '<passwordHash>#jbcrypt:.+</passwordHash>',
88+
"<passwordHash>#jbcrypt:$([bcrypt.net.bcrypt]::hashpassword($JenkinsCred.Password, $Salt))</passwordHash>" |
89+
Set-Content $AdminUserPath -Force
90+
#endregion
91+
4992
# Long winded way to get the scripts for Jenkins jobs into the right place, but easier to maintain going forward
5093
$root = Split-Path -Parent $MyInvocation.MyCommand.Definition
5194
$systemRoot = $env:SystemDrive + '\'
@@ -59,109 +102,132 @@ process {
59102

60103
Stop-Service -Name Jenkins
61104

62-
Write-Host "Updating Jenkins plugins" -ForegroundColor Green
105+
#region Jenkins Plugin Install & Update
106+
# Defining required plugins
63107
$JenkinsPlugins = @{
64-
'ant' = '481.v7b_09e538fcca'
108+
'ant' = '487.vd79d090d4ea_e'
65109
'apache-httpcomponents-client-4-api' = '4.5.14-150.v7a_b_9d17134a_5'
66-
'bootstrap5-api' = '5.2.2-1'
67-
'bouncycastle-api' = '2.27'
68-
'branch-api' = '2.1071.v1a_188a_562481'
69-
'build-timeout' = '1.28'
70-
'caffeine-api' = '2.9.3-65.v6a_47d0f4d1fe'
110+
'bootstrap5-api' = '5.2.2-5'
111+
'bouncycastle-api' = '2.28'
112+
'branch-api' = '2.1092.vda_3c2a_a_f0c11'
113+
'build-timeout' = '1.30'
114+
'caffeine-api' = '3.1.6-115.vb_8b_b_328e59d8'
71115
'checks-api' = '2.0.0'
72116
'commons-lang3-api' = '3.12.0-36.vd97de6465d5b_'
73117
'commons-text-api' = '1.10.0-36.vc008c8fcda_7b_'
74-
'credentials-binding' = '523.vd859a_4b_122e6'
75-
'credentials' = '1224.vc23ca_a_9a_2cb_0'
118+
'credentials-binding' = '604.vb_64480b_c56ca_'
119+
'credentials' = '1254.vb_96f366e7b_a_d'
76120
'display-url-api' = '2.3.7'
77-
'durable-task' = '504.vb10d1ae5ba2f'
78-
'echarts-api' = '5.4.0-2'
79-
'email-ext' = '2.95'
121+
'durable-task' = '507.v050055d0cb_dd'
122+
'echarts-api' = '5.4.0-4'
123+
'email-ext' = '2.97'
80124
'cloudbees-folder' = '6.815.v0dd5a_cb_40e0e'
81-
'font-awesome-api' = '6.3.0-1'
125+
'font-awesome-api' = '6.3.0-2'
82126
'git-client' = '4.2.0'
83-
'git' = '5.0.0'
84-
'github-api' = '1.303-417.ve35d9dd78549'
85-
'github-branch-source' = '1701.v00cc8184df93'
86-
'github' = '1.37.0'
87-
'gradle' = '2.3.2'
127+
'git' = '5.0.2'
128+
'github-api' = '1.314-431.v78d72a_3fe4c3'
129+
'github-branch-source' = '1703.vd5a_2b_29c6cdc'
130+
'github' = '1.37.1'
131+
'gradle' = '2.7'
88132
'instance-identity' = '142.v04572ca_5b_265'
89-
'ionicons-api' = '45.vf54fca_5d2154'
90-
'jackson2-api' = '2.14.2-319.v37853346a_229'
133+
'ionicons-api' = '56.v1b_1c8c49374e'
134+
'jackson2-api' = '2.15.1-344.v6eb_55303dc3e'
91135
'jakarta-activation-api' = '2.0.1-3'
92136
'jakarta-mail-api' = '2.0.1-3'
93137
'jjwt-api' = '0.11.5-77.v646c772fddb_0'
94138
'javax-activation-api' = '1.2.0-6'
95139
'javax-mail-api' = '1.6.2-9'
96140
'jaxb' = '2.3.8-1'
97-
'jquery3-api' = '3.6.3-1'
98-
'junit' = '1189.v1b_e593637fa_e'
99-
'ldap' = '671.v2a_9192a_7419d'
141+
'jquery3-api' = '3.7.0-1'
142+
'junit' = '1202.v79a_986785076'
143+
'ldap' = '682.v7b_544c9d1512'
100144
'mailer' = '448.v5b_97805e3767'
101-
'matrix-auth' = '3.1.6'
102-
'matrix-project' = '785.v06b_7f47b_c631'
103-
'mina-sshd-api-common' = '2.9.2-50.va_0e1f42659a_a'
104-
'mina-sshd-api-core' = '2.9.2-50.va_0e1f42659a_a'
145+
'matrix-auth' = '3.1.7'
146+
'matrix-project' = '789.v57a_725b_63c79'
147+
'mina-sshd-api-common' = '2.10.0-69.v28e3e36d18eb_'
148+
'mina-sshd-api-core' = '2.10.0-69.v28e3e36d18eb_'
105149
'okhttp-api' = '4.10.0-132.v7a_7b_91cef39c'
106150
'antisamy-markup-formatter' = '159.v25b_c67cd35fb_'
107151
'pam-auth' = '1.10'
108152
'workflow-aggregator' = '596.v8c21c963d92d'
109153
'pipeline-graph-analysis' = '202.va_d268e64deb_3'
110-
'workflow-api' = '1208.v0cc7c6e0da_9e'
111-
'workflow-basic-steps' = '1010.vf7a_b_98e847c1'
112-
'pipeline-build-step' = '487.va_823138eee8b_'
113-
'pipeline-model-definition' = '2.2121.vd87fb_6536d1e'
114-
'pipeline-model-extensions' = '2.2121.vd87fb_6536d1e'
154+
'workflow-api' = '1213.v646def1087f9'
155+
'workflow-basic-steps' = '1017.vb_45b_302f0cea_'
156+
'pipeline-build-step' = '491.v1fec530da_858'
157+
'pipeline-model-definition' = '2.2131.vb_9788088fdb_5'
158+
'pipeline-model-extensions' = '2.2131.vb_9788088fdb_5'
115159
'pipeline-github-lib' = '42.v0739460cda_c4'
116-
'workflow-cps' = '3641.vf58904a_b_b_5d8'
117-
'pipeline-groovy-lib' = '629.vb_5627b_ee2104'
118-
'pipeline-input-step' = '466.v6d0a_5df34f81'
119-
'workflow-job' = '1284.v2fe8ed4573d4'
160+
'workflow-cps' = '3668.v1763b_b_6ccffd'
161+
'pipeline-groovy-lib' = '656.va_a_ceeb_6ffb_f7'
162+
'pipeline-input-step' = '468.va_5db_051498a_4'
163+
'workflow-job' = '1295.v395eb_7400005'
120164
'pipeline-milestone-step' = '111.v449306f708b_7'
121-
'pipeline-model-api' = '2.2121.vd87fb_6536d1e'
122-
'workflow-multibranch' = '733.v109046189126'
123-
'workflow-durable-task-step' = '1234.v019404b_3832a'
124-
'pipeline-rest-api' = '2.31'
125-
'workflow-scm-step' = '400.v6b_89a_1317c9a_'
165+
'pipeline-model-api' = '2.2131.vb_9788088fdb_5'
166+
'workflow-multibranch' = '746.v05814d19c001'
167+
'workflow-durable-task-step' = '1246.v5524618ea_097'
168+
'pipeline-rest-api' = '2.32'
169+
'workflow-scm-step' = '408.v7d5b_135a_b_d49'
126170
'pipeline-stage-step' = '305.ve96d0205c1c6'
127-
'pipeline-stage-tags-metadata' = '2.2121.vd87fb_6536d1e'
128-
'pipeline-stage-view' = '2.31'
171+
'pipeline-stage-tags-metadata' = '2.2131.vb_9788088fdb_5'
172+
'pipeline-stage-view' = '2.32'
129173
'workflow-step-api' = '639.v6eca_cd8c04a_a_'
130174
'workflow-support' = '839.v35e2736cfd5c'
131175
'plain-credentials' = '143.v1b_df8b_d3b_e48'
132-
'plugin-util-api' = '3.1.0'
176+
'plugin-util-api' = '3.2.1'
133177
'powershell' = '2.0'
134-
'resource-disposer' = '0.21'
135-
'scm-api' = '631.v9143df5b_e4a_a'
136-
'script-security' = '1229.v4880b_b_e905a_6'
178+
'resource-disposer' = '0.22'
179+
'scm-api' = '672.v64378a_b_20c60'
180+
'script-security' = '1244.ve463715a_f89c'
137181
'snakeyaml-api' = '1.33-95.va_b_a_e3e47b_fa_4'
138182
'ssh-slaves' = '2.877.v365f5eb_a_b_eec'
139183
'ssh-credentials' = '305.v8f4381501156'
140-
'sshd' = '3.275.v9e17c10f2571'
184+
'sshd' = '3.303.vefc7119b_ec23'
141185
'structs' = '324.va_f5d6774f3a_d'
142-
'timestamper' = '1.22'
143-
'token-macro' = '321.vd7cc1f2a_52c8'
186+
'timestamper' = '1.25'
187+
'token-macro' = '359.vb_cde11682e0c'
144188
'trilead-api' = '2.84.v72119de229b_7'
145189
'variant' = '59.vf075fe829ccb'
146-
'ws-cleanup' = '0.44'
190+
'ws-cleanup' = '0.45'
147191
}
148192

193+
# Performance is killed by Invoke-WebRequest's progress bars, turning them off to speed this up
194+
$ProgressPreference = 'SilentlyContinue'
195+
196+
# Downloading Jenkins Plugins
197+
Write-Host "Downloading Jenkins Plugins"
149198
foreach ($PluginName in $JenkinsPlugins.Keys) {
150-
$PluginUri = 'https://updates.jenkins-ci.org/download/plugins/{0}/{1}/{0}.hpi' -f $PluginName,$JenkinsPlugins[$PluginName]
151-
$PluginPath = '{0}/plugins/{1}.hpi' -f $JenkinsHome, $PluginName
152-
[System.Net.WebClient]::New().DownloadFile($PluginUri,$PluginPath)
199+
$PluginUri = if ($JenkinsPlugins[$PluginName] -ne "latest") {
200+
'https://updates.jenkins-ci.org/download/plugins/{0}/{1}/{0}.hpi' -f $PluginName, $JenkinsPlugins[$PluginName]
201+
}
202+
else {
203+
"https://updates.jenkins-ci.org/latest/$($PluginName).hpi"
204+
}
205+
$PluginPath = '{0}/plugins/{1}.hpi' -f $jenkinsHome, $PluginName
206+
if (-not (Test-Path $PluginPath)) {
207+
try {
208+
Invoke-WebRequest -Uri $PluginUri -OutFile $PluginPath -UseBasicParsing -ErrorAction Stop
209+
}
210+
catch {
211+
# We have internalized the required plugins for jobs we provide
212+
Write-Warning "Could not download '$($PluginName)' from '$($PluginUri)': $($_)"
213+
}
214+
}
153215
}
154216

217+
# Restore default progress bar setting
218+
$ProgressPreference = 'Continue'
219+
#endregion
220+
155221
#region Job Config
156222
Write-Host "Creating Chocolatey Jobs" -ForegroundColor Green
157223
Get-ChildItem "$env:SystemDrive\choco-setup\files\jenkins" | Copy-Item -Destination "$JenkinsHome\jobs\" -Recurse
158224

159225

160226
Get-ChildItem -Path "$JenkinsHome\jobs" -Recurse -File -Filter 'config.xml' | ForEach-Object {
161227
(Get-Content -Path $_.FullName -Raw) -replace
162-
'{{NugetApiKey}}', $NuGetApiKey -replace
163-
'{{hostname}}', $HostName |
164-
Set-Content -Path $_.FullName
228+
'{{NugetApiKey}}', $NuGetApiKey -replace
229+
'{{hostname}}', $HostName |
230+
Set-Content -Path $_.FullName
165231
}
166232
#endregion
167233

@@ -170,16 +236,16 @@ process {
170236

171237
# Save useful params to JSON
172238
$JenkinsJson = @{
173-
JenkinsUri = "http://localhost:8080"
239+
JenkinsUri = "http://$($HostName):8080"
174240
JenkinsUser = "admin"
175-
JenkinsPw = $(Get-Content "$JenkinsHome\secrets\initialAdminPassword")
241+
JenkinsPw = $JenkinsCred.Password
176242
}
177243
$JenkinsJson | ConvertTo-Json | Out-File "$env:SystemDrive\choco-setup\logs\jenkins.json"
178244

179245
Write-Host 'Jenkins setup complete' -ForegroundColor Green
180-
Write-Host 'Login to Jenkins at: http://locahost:8080' -ForegroundColor Green
246+
Write-Host 'Login to Jenkins at: http://$($HostName):8080' -ForegroundColor Green
181247
Write-Host 'Initial default Jenkins admin user password:' -ForegroundColor Green
182-
Write-Host "$(Get-Content "$JenkinsHome\secrets\initialAdminPassword")" -ForegroundColor Green
248+
Write-Host "Admin Password is '$($JenkinsCred.Password)'" -ForegroundColor Green
183249

184250
Write-Host 'Writing README to Desktop; this file contains login information for all C4B services.'
185251
New-QuickstartReadme
@@ -216,10 +282,10 @@ process {
216282
$Nexus = "https://${hostname}:8443"
217283
$Jenkins = 'http://localhost:8080'
218284
try {
219-
Start-Process msedge.exe "$Readme","$Ccm", "$Nexus", "$Jenkins"
285+
Start-Process msedge.exe "$Readme", "$Ccm", "$Nexus", "$Jenkins"
220286
}
221287
catch {
222-
Start-Process chrome.exe "$Readme","$Ccm", "$Nexus", "$Jenkins"
288+
Start-Process chrome.exe "$Readme", "$Ccm", "$Nexus", "$Jenkins"
223289
}
224290
}
225291

jenkins/Internalize packages from the Community Repository/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@
5959
<sandbox>true</sandbox>
6060
</definition>
6161
<triggers/>
62-
<disabled>true</disabled>
62+
<disabled>false</disabled>
6363
</flow-definition>

jenkins/Update production repository/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@
5555
<sandbox>true</sandbox>
5656
</definition>
5757
<triggers/>
58-
<disabled>true</disabled>
58+
<disabled>false</disabled>
5959
</flow-definition>

jenkins/Update test repository from Chocolatey Community Repository/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@
3939
<sandbox>true</sandbox>
4040
</definition>
4141
<triggers/>
42-
<disabled>true</disabled>
42+
<disabled>false</disabled>
4343
</flow-definition>

scripts/Get-Helpers.ps1

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,41 @@ function Set-CcmCertificate {
16051605

16061606
#endregion
16071607

1608+
#region Jenkins Setup
1609+
1610+
# Function to generate Jenkins password
1611+
function New-ServicePassword {
1612+
<#
1613+
.Synopsis
1614+
Generates and returns a suitably secure password suited for support calls
1615+
#>
1616+
[CmdletBinding()]
1617+
[OutputType([System.Security.SecureString])]
1618+
param(
1619+
[ValidateRange(1,128)]
1620+
[int]$Length = 64,
1621+
1622+
[char[]]$AvailableCharacters = @(
1623+
# Specifically excluding $, `, ;, #, etc such that pasting
1624+
# passwords into support scripts will be more predictable.
1625+
"!%()*+,-./<=>?@[\]^_"
1626+
48..57 # 0-9
1627+
65..90 # A-Z
1628+
97..122 # a-z
1629+
).ForEach{[char[]]$_}
1630+
)
1631+
end {
1632+
$NewPassword = [System.Security.SecureString]::new()
1633+
1634+
while ($NewPassword.Length -lt $Length) {
1635+
$NewPassword.AppendChar(($AvailableCharacters | Get-Random))
1636+
}
1637+
1638+
$NewPassword
1639+
}
1640+
}
1641+
#endregion
1642+
16081643
#region README functions
16091644
function Remove-JsonFiles {
16101645
<#
@@ -1654,7 +1689,7 @@ The host name of the C4B instance.
16541689

16551690
process {
16561691
$nexusPassword = Get-Content -Path 'C:\ProgramData\sonatype-work\nexus3\admin.password'
1657-
$jenkinsPassword = Get-Content -path 'C:\ProgramData\Jenkins\.jenkins\secrets\initialAdminPassword'
1692+
$jenkinsPassword = (Get-Content "$env:SystemDrive\choco-setup\logs\jenkins.json" | ConvertFrom-Json).JenkinsPw
16581693
$nexusApiKey = (Get-Content "$env:SystemDrive\choco-setup\logs\nexus.json" | ConvertFrom-Json).NuGetApiKey
16591694

16601695
$tableData = @([pscustomobject]@{
@@ -1701,7 +1736,7 @@ The host name of the C4B instance.
17011736
}</style>
17021737
<body>
17031738
<blockquote>
1704-
<p>📝 <strong>Note</strong></p>
1739+
<p><strong>Note</strong></p>
17051740
<p>The following table provides the default credentials to login to each of the services made available as part of the Quickstart Guide setup process.</p>
17061741
You'll be asked to change the credentials upon logging into each service for the first time.
17071742
Document your new credentials in a password manager, or whatever system you use.

0 commit comments

Comments
 (0)