@@ -5,8 +5,6 @@ $global:SUT_IMAGE=Get-SutImage
55$global :SUT_CONTAINER = Get-SutImage
66$global :TEST_TAG = $global :SUT_IMAGE.Replace (' pester-jenkins-' , ' ' )
77
8- $global :WORK = Join-Path $PSScriptRoot " upgrade-plugins/work-${ global:SUT_IMAGE } "
9-
108Describe " [plugins-cli > $global :TEST_TAG ] build image" {
119 BeforeEach {
1210 Push-Location - StackName ' jenkins' - Path " $PSScriptRoot /.."
@@ -150,43 +148,35 @@ Describe "[plugins-cli > $global:TEST_TAG] plugins are installed with jenkins-pl
150148 $exitCode , $stdout , $stderr = Build-DockerChild $global :SUT_IMAGE - plugins- cli- update $PSScriptRoot / plugins- cli/ update -- no- cache
151149 $exitCode | Should - Be 0
152150 }
153-
151+
154152 It ' has the correct version of junit' {
155153 $exitCode , $stdout , $stderr = Run- Program ' docker.exe' " run --rm $global :SUT_IMAGE -plugins-cli-update Import-Module -Force -DisableNameChecking C:/ProgramData/Jenkins/jenkins-support.psm1 ; Expand-Zip `$ env:JENKINS_HOME/plugins/junit.jpi 'META-INF/MANIFEST.MF'"
156154 $exitCode | Should - Be 0
157155 $stdout | Should -Match ' Plugin-Version: 1.28'
158156 }
159157}
160158
161- Describe " [plugins-cli > $global :TEST_TAG ] clean work directory" {
162- It ' cleanup' {
163- if (Test-Path $PSScriptRoot / upgrade- plugins/ work- $global :SUT_IMAGE ) {
164- Remove-Item - Recurse - Force $PSScriptRoot / upgrade- plugins/ work- $global :SUT_IMAGE | Out-Null
165- }
166- }
167- }
168-
169159# Only test on Java 21, one JDK is enough to test all versions
170160Describe " [plugins-cli > $global :TEST_TAG ] plugins are getting upgraded but not downgraded" - Skip:(-not $global :TEST_TAG.Contains (' jdk21-' )) {
161+ BeforeAll {
162+ $dockerVolume = (New-Guid ).Guid
163+ docker volume rm -f $dockerVolume
164+ }
171165 It ' builds child image' {
172166 # Initial execution
173167 $exitCode , $stdout , $stderr = Build-DockerChild $global :SUT_IMAGE - plugins- cli $PSScriptRoot / plugins- cli
174168 $exitCode | Should - Be 0
175169 }
176170
177171 It ' has correct version of junit and ant plugins' {
178- if (-not (Test-Path $global :WORK )) {
179- New-Item - ItemType Directory - Path $global :WORK
180- }
181-
182172 # Image contains junit 1.6 and ant-plugin 1.3
183- $exitCode , $stdout , $stderr = Run- Program ' docker.exe' " run -v `" ${work } :C:\ProgramData\Jenkins\JenkinsHome`" --rm $global :SUT_IMAGE -plugins-cli exit 0"
173+ $exitCode , $stdout , $stderr = Run- Program ' docker.exe' " run -v ${dockerVolume } :C:\ProgramData\Jenkins\JenkinsHome --rm $global :SUT_IMAGE -plugins-cli exit 0"
184174 $exitCode | Should - Be 0
185175
186- $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE " junit.jpi" $global :WORK
176+ $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE " junit.jpi" $dockerVolume
187177 $exitCode | Should - Be 0
188178 $stdout | Should -Match ' Plugin-Version: 1.6'
189- $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE " ant.jpi" $global :WORK
179+ $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE " ant.jpi" $dockerVolume
190180 $exitCode | Should - Be 0
191181 $stdout | Should -Match ' Plugin-Version: 1.3'
192182 }
@@ -196,121 +186,107 @@ Describe "[plugins-cli > $global:TEST_TAG] plugins are getting upgraded but not
196186 $exitCode , $stdout , $stderr = Build-DockerChild $global :SUT_IMAGE - upgrade- plugins $PSScriptRoot / upgrade- plugins
197187 $exitCode | Should - Be 0
198188 # Images contains junit 1.28 and ant-plugin 1.2
199- $exitCode , $stdout , $stderr = Run- Program ' docker.exe' " run -v `" ${work } :C:\ProgramData\Jenkins\JenkinsHome`" --rm $global :SUT_IMAGE -upgrade-plugins exit 0"
189+ $exitCode , $stdout , $stderr = Run- Program ' docker.exe' " run -v ${dockerVolume } :C:\ProgramData\Jenkins\JenkinsHome --rm $global :SUT_IMAGE -upgrade-plugins exit 0"
200190 $exitCode | Should - Be 0
201- $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' junit.jpi' $global :WORK
191+ $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' junit.jpi' $dockerVolume
202192 $exitCode | Should - Be 0
203193 # Should be updated
204194 $stdout | Should -Match ' Plugin-Version: 1.28'
205- $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' ant.jpi' $global :WORK
195+ $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' ant.jpi' $dockerVolume
206196 $exitCode | Should - Be 0
207197 # 1.2 is older than the existing 1.3, so keep 1.3
208198 $stdout | Should -Match ' Plugin-Version: 1.3'
209199 }
210- }
211-
212- Describe " [plugins-cli > $global :TEST_TAG ] clean work directory" {
213- It ' cleanup' {
214- if (Test-Path $global :WORK ) {
215- Remove-Item - Recurse - Force $global :WORK | Out-Null
216- }
200+ AfterAll {
201+ docker volume rm -f $dockerVolume
217202 }
218203}
219204
220205# Only test on Java 21, one JDK is enough to test all versions
221206Describe " [plugins-cli > $global :TEST_TAG ] do not upgrade if plugin has been manually updated" - Skip:(-not $global :TEST_TAG.Contains (' jdk21-' )) {
222-
207+ BeforeAll {
208+ $dockerVolume = (New-Guid ).Guid
209+ docker volume rm -f $dockerVolume
210+ }
211+
223212 It ' builds child image' {
224213 $exitCode , $stdout , $stderr = Build-DockerChild $global :SUT_IMAGE - plugins- cli $PSScriptRoot / plugins- cli
225214 $exitCode | Should - Be 0
226215 }
227216
228217 It ' updates plugin manually and then via plugin-cli' {
229- if (-not (Test-Path $global :WORK )) {
230- New-Item - ItemType Directory - Path $global :WORK
231- }
232-
233218 # Image contains junit 1.8 and ant-plugin 1.3
234- $exitCode , $stdout , $stderr = Run- Program ' docker.exe' " run -v `" ${work } :C:\ProgramData\Jenkins\JenkinsHome`" --rm $global :SUT_IMAGE -plugins-cli curl.exe --connect-timeout 20 --retry 5 --retry-delay 0 --retry-max-time 60 -s -f -L https://updates.jenkins.io/download/plugins/junit/1.8/junit.hpi -o C:/ProgramData/Jenkins/JenkinsHome/plugins/junit.jpi"
219+ $exitCode , $stdout , $stderr = Run- Program ' docker.exe' " run -v ${dockerVolume } :C:\ProgramData\Jenkins\JenkinsHome --rm $global :SUT_IMAGE -plugins-cli curl.exe --connect-timeout 20 --retry 5 --retry-delay 0 --retry-max-time 60 -s -f -L https://updates.jenkins.io/download/plugins/junit/1.8/junit.hpi -o C:/ProgramData/Jenkins/JenkinsHome/plugins/junit.jpi"
235220 $exitCode | Should - Be 0
236- $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' junit.jpi' $global :WORK
221+ $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' junit.jpi' $dockerVolume
237222 $exitCode | Should - Be 0
238223 $stdout | Should -Match ' Plugin-Version: 1.8'
239- $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' ant.jpi' $global :WORK
224+ $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' ant.jpi' $dockerVolume
240225 $exitCode | Should - Be 0
241226 $stdout | Should -Match ' Plugin-Version: 1.3'
242227
243228 $exitCode , $stdout , $stderr = Build-DockerChild $global :SUT_IMAGE - upgrade- plugins $PSScriptRoot / upgrade- plugins
244229 $exitCode | Should - Be 0
245230
246231 # Images contains junit 1.28 and ant-plugin 1.2
247- $exitCode , $stdout , $stderr = Run- Program ' docker.exe' " run -v `" ${work } :C:\ProgramData\Jenkins\JenkinsHome`" --rm $global :SUT_IMAGE -upgrade-plugins exit 0"
232+ $exitCode , $stdout , $stderr = Run- Program ' docker.exe' " run -v ${dockerVolume } :C:\ProgramData\Jenkins\JenkinsHome --rm $global :SUT_IMAGE -upgrade-plugins exit 0"
248233 $exitCode | Should - Be 0
249234 # junit shouldn't be upgraded
250- $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' junit.jpi' $global :WORK
235+ $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' junit.jpi' $dockerVolume
251236 $exitCode | Should - Be 0
252237 $stdout | Should -Match ' Plugin-Version: 1.8'
253238 $stdout | Should -Not -Match ' Plugin-Version: 1.28'
254239 # ant shouldn't be downgraded
255- $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' ant.jpi' $global :WORK
240+ $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' ant.jpi' $dockerVolume
256241 $exitCode | Should - Be 0
257242 $stdout | Should -Match ' Plugin-Version: 1.3'
258243 $stdout | Should -Not -Match ' Plugin-Version: 1.2'
259244 }
260- }
261-
262- Describe " [plugins-cli > $global :TEST_TAG ] clean work directory" {
263- It ' cleanup' {
264- if (Test-Path $global :WORK ) {
265- Remove-Item - Recurse - Force $global :WORK | Out-Null
266- }
245+ AfterAll {
246+ docker volume rm -f $dockerVolume
267247 }
268248}
269249
270250# Only test on Java 21, one JDK is enough to test all versions
271251Describe " [plugins-cli > $global :TEST_TAG ] upgrade plugin even if it has been manually updated when PLUGINS_FORCE_UPGRADE=true" - Skip:(-not $global :TEST_TAG.Contains (' jdk21-' )) {
252+ BeforeAll {
253+ $dockerVolume = (New-Guid ).Guid
254+ docker volume rm -f $dockerVolume
255+ }
256+
272257 It ' builds child image' {
273258 $exitCode , $stdout , $stderr = Build-DockerChild $global :SUT_IMAGE - plugins- cli $PSScriptRoot / plugins- cli
274259 $exitCode | Should - Be 0
275260 }
276261
277262 It ' upgrades plugins' {
278- if (-not (Test-Path $global :WORK )) {
279- New-Item - ItemType Directory - Path $global :WORK
280- }
281-
282263 # Image contains junit 1.6 and ant-plugin 1.3
283- $exitCode , $stdout , $stderr = Run- Program ' docker.exe' " run -v `" ${work } :C:\ProgramData\Jenkins\JenkinsHome`" --rm $global :SUT_IMAGE -plugins-cli curl.exe --connect-timeout 20 --retry 5 --retry-delay 0 --retry-max-time 60 -s -f -L https://updates.jenkins.io/download/plugins/junit/1.8/junit.hpi -o C:/ProgramData/Jenkins/JenkinsHome/plugins/junit.jpi"
264+ $exitCode , $stdout , $stderr = Run- Program ' docker.exe' " run -v ${dockerVolume } :C:\ProgramData\Jenkins\JenkinsHome --rm $global :SUT_IMAGE -plugins-cli curl.exe --connect-timeout 20 --retry 5 --retry-delay 0 --retry-max-time 60 -s -f -L https://updates.jenkins.io/download/plugins/junit/1.8/junit.hpi -o C:/ProgramData/Jenkins/JenkinsHome/plugins/junit.jpi"
284265 $exitCode | Should - Be 0
285266
286- $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' junit.jpi' $global :WORK
267+ $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' junit.jpi' $dockerVolume
287268 $exitCode | Should - Be 0
288269 $stdout | Should -Match ' Plugin-Version: 1.8'
289-
270+
290271 $exitCode , $stdout , $stderr = Build-DockerChild $global :SUT_IMAGE - upgrade- plugins $PSScriptRoot / upgrade- plugins
291272 $exitCode | Should - Be 0
292-
273+
293274 # Images contains junit 1.28 and ant-plugin 1.2
294- $exitCode , $stdout , $stderr = Run- Program ' docker.exe' " run -e PLUGINS_FORCE_UPGRADE=true -v ${work } :C:/ ProgramData/ Jenkins/ JenkinsHome --rm $global :SUT_IMAGE -upgrade-plugins exit 0"
275+ $exitCode , $stdout , $stderr = Run- Program ' docker.exe' " run -e PLUGINS_FORCE_UPGRADE=true -v ${dockerVolume } :C:\ ProgramData\ Jenkins\ JenkinsHome --rm $global :SUT_IMAGE -upgrade-plugins exit 0" true
295276 $exitCode | Should - Be 0
296277 # junit should be upgraded
297- $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' junit.jpi' $global :WORK
278+ $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' junit.jpi' $dockerVolume
298279 $exitCode | Should - Be 0
299280 $stdout | Should -Not -Match ' Plugin-Version: 1.8'
300281 $stdout | Should -Match ' Plugin-Version: 1.28'
301282 # ant shouldn't be downgraded
302- $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' ant.jpi' $global :WORK
283+ $exitCode , $stdout , $stderr = Unzip- Manifest $global :SUT_IMAGE ' ant.jpi' $dockerVolume
303284 $exitCode | Should - Be 0
304285 $stdout | Should -Match ' Plugin-Version: 1.3'
305286 $stdout | Should -Not -Match ' Plugin-Version: 1.2'
306287 }
307- }
308-
309- Describe " [plugins-cli > $global :TEST_TAG ] clean work directory" {
310- It ' cleanup' {
311- if (Test-Path $global :WORK ) {
312- Remove-Item - Recurse - Force $global :WORK | Out-Null
313- }
288+ AfterAll {
289+ docker volume rm -f $dockerVolume
314290 }
315291}
316292
@@ -329,11 +305,3 @@ Describe "[plugins-cli > $global:TEST_TAG] Use a custom jenkins.war" -Skip:(-not
329305 $exitCode | Should - Be 0
330306 }
331307}
332-
333- Describe " [plugins-cli > $global :TEST_TAG ] clean work directory" {
334- It ' cleanup' {
335- if (Test-Path $global :WORK ) {
336- Remove-Item - Recurse - Force $global :WORK | Out-Null
337- }
338- }
339- }
0 commit comments