19
19
)
20
20
21
21
begin {
22
- if ($host.name -ne ' ConsoleHost' ) {
22
+ if ($host.name -ne ' ConsoleHost' ) {
23
23
Write-Warning " This script cannot be ran from within PowerShell ISE"
24
24
Write-Warning " Please launch powershell.exe as an administrator, and run this script again"
25
25
break
@@ -39,13 +39,56 @@ process {
39
39
$chocoArgs = @ (' install' , ' temurin11jre' , ' -y' , " --source='$Source '" , ' --no-progress' )
40
40
& choco @chocoArgs
41
41
42
+ # Enviornment variable used to disbale jenkins instal login prompts
43
+ [Environment ]::SetEnvironmentVariable(' JAVA_OPTS' , ' -Djenkins.install.runSetupWizard=false' , ' Machine' )
44
+
42
45
# Install Jenkins
43
- $chocoArgs = @ (' install' , ' jenkins' , ' -y' , " --source='$Source '" , ' --no-progress' )
46
+ $chocoArgs = @ (' install' , ' jenkins' , ' --version=2.401.2 ' , ' - y' , " --source='$Source '" , ' --no-progress' )
44
47
& choco @chocoArgs
45
48
46
49
Write-Host " Giving Jenkins 30 seconds to complete background setup..." - ForegroundColor Green
47
50
Start-Sleep - Seconds 30 # Jenkins needs a moment
48
51
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 <nobody@nowhere></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
+
49
92
# Long winded way to get the scripts for Jenkins jobs into the right place, but easier to maintain going forward
50
93
$root = Split-Path - Parent $MyInvocation.MyCommand.Definition
51
94
$systemRoot = $env: SystemDrive + ' \'
@@ -59,109 +102,132 @@ process {
59
102
60
103
Stop-Service - Name Jenkins
61
104
62
- Write-Host " Updating Jenkins plugins" - ForegroundColor Green
105
+ # region Jenkins Plugin Install & Update
106
+ # Defining required plugins
63
107
$JenkinsPlugins = @ {
64
- ' ant' = ' 481.v7b_09e538fcca '
108
+ ' ant' = ' 487.vd79d090d4ea_e '
65
109
' 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 '
71
115
' checks-api' = ' 2.0.0'
72
116
' commons-lang3-api' = ' 3.12.0-36.vd97de6465d5b_'
73
117
' 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 '
76
120
' 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 '
80
124
' cloudbees-folder' = ' 6.815.v0dd5a_cb_40e0e'
81
- ' font-awesome-api' = ' 6.3.0-1 '
125
+ ' font-awesome-api' = ' 6.3.0-2 '
82
126
' 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 '
88
132
' 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 '
91
135
' jakarta-activation-api' = ' 2.0.1-3'
92
136
' jakarta-mail-api' = ' 2.0.1-3'
93
137
' jjwt-api' = ' 0.11.5-77.v646c772fddb_0'
94
138
' javax-activation-api' = ' 1.2.0-6'
95
139
' javax-mail-api' = ' 1.6.2-9'
96
140
' 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 '
100
144
' 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_ '
105
149
' okhttp-api' = ' 4.10.0-132.v7a_7b_91cef39c'
106
150
' antisamy-markup-formatter' = ' 159.v25b_c67cd35fb_'
107
151
' pam-auth' = ' 1.10'
108
152
' workflow-aggregator' = ' 596.v8c21c963d92d'
109
153
' 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 '
115
159
' 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 '
120
164
' 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 '
126
170
' 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 '
129
173
' workflow-step-api' = ' 639.v6eca_cd8c04a_a_'
130
174
' workflow-support' = ' 839.v35e2736cfd5c'
131
175
' plain-credentials' = ' 143.v1b_df8b_d3b_e48'
132
- ' plugin-util-api' = ' 3.1.0 '
176
+ ' plugin-util-api' = ' 3.2.1 '
133
177
' 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 '
137
181
' snakeyaml-api' = ' 1.33-95.va_b_a_e3e47b_fa_4'
138
182
' ssh-slaves' = ' 2.877.v365f5eb_a_b_eec'
139
183
' ssh-credentials' = ' 305.v8f4381501156'
140
- ' sshd' = ' 3.275.v9e17c10f2571 '
184
+ ' sshd' = ' 3.303.vefc7119b_ec23 '
141
185
' 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 '
144
188
' trilead-api' = ' 2.84.v72119de229b_7'
145
189
' variant' = ' 59.vf075fe829ccb'
146
- ' ws-cleanup' = ' 0.44 '
190
+ ' ws-cleanup' = ' 0.45 '
147
191
}
148
192
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"
149
198
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
+ }
153
215
}
154
216
217
+ # Restore default progress bar setting
218
+ $ProgressPreference = ' Continue'
219
+ # endregion
220
+
155
221
# region Job Config
156
222
Write-Host " Creating Chocolatey Jobs" - ForegroundColor Green
157
223
Get-ChildItem " $env: SystemDrive \choco-setup\files\jenkins" | Copy-Item - Destination " $JenkinsHome \jobs\" - Recurse
158
224
159
225
160
226
Get-ChildItem - Path " $JenkinsHome \jobs" - Recurse - File - Filter ' config.xml' | ForEach-Object {
161
227
(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
165
231
}
166
232
# endregion
167
233
@@ -170,16 +236,16 @@ process {
170
236
171
237
# Save useful params to JSON
172
238
$JenkinsJson = @ {
173
- JenkinsUri = " http://localhost :8080"
239
+ JenkinsUri = " http://$ ( $HostName ) :8080"
174
240
JenkinsUser = " admin"
175
- JenkinsPw = $ ( Get-Content " $JenkinsHome \secrets\initialAdminPassword " )
241
+ JenkinsPw = $JenkinsCred .Password
176
242
}
177
243
$JenkinsJson | ConvertTo-Json | Out-File " $env: SystemDrive \choco-setup\logs\jenkins.json"
178
244
179
245
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
181
247
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
183
249
184
250
Write-Host ' Writing README to Desktop; this file contains login information for all C4B services.'
185
251
New-QuickstartReadme
@@ -216,10 +282,10 @@ process {
216
282
$Nexus = " https://${hostname} :8443"
217
283
$Jenkins = ' http://localhost:8080'
218
284
try {
219
- Start-Process msedge.exe " $Readme " , " $Ccm " , " $Nexus " , " $Jenkins "
285
+ Start-Process msedge.exe " $Readme " , " $Ccm " , " $Nexus " , " $Jenkins "
220
286
}
221
287
catch {
222
- Start-Process chrome.exe " $Readme " , " $Ccm " , " $Nexus " , " $Jenkins "
288
+ Start-Process chrome.exe " $Readme " , " $Ccm " , " $Nexus " , " $Jenkins "
223
289
}
224
290
}
225
291
0 commit comments