6
6
[String ] $RemotingVersion = ' 3180.v3dd999d24861' ,
7
7
[String ] $BuildNumber = ' 1' ,
8
8
[switch ] $PushVersions = $false ,
9
- [switch ] $DisableEnvProps = $false
9
+ [switch ] $DisableEnvProps = $false ,
10
+ [switch ] $DryRun = $false
10
11
)
11
12
12
13
$ErrorActionPreference = ' Stop'
@@ -108,16 +109,19 @@ Invoke-Expression "$baseDockerCmd config --services" 2>$null | ForEach-Object {
108
109
Write-Host " = PREPARE: List of $Organization /$Repository images and tags to be processed:"
109
110
ConvertTo-Json $builds
110
111
112
+ $dockerBuildCmd = $baseDockerBuildCmd
113
+ $current = ' all images'
111
114
if (! [System.String ]::IsNullOrWhiteSpace($Build ) -and $builds.ContainsKey ($Build )) {
112
- Write-Host " = BUILD: Building image ${ Build} ... "
115
+ $current = " $ Build image "
113
116
$dockerBuildCmd = ' {0} {1}' -f $baseDockerBuildCmd , $Build
114
- Invoke-Expression $dockerBuildCmd
115
- Write-Host " = BUILD: Finished building image ${Build} "
117
+ }
118
+ Write-Host " = BUILD: Building ${current} ..."
119
+ if ($DryRun ) {
120
+ Write-Host " (dry-run) $dockerBuildCmd "
116
121
} else {
117
- Write-Host " = BUILD: Building all images..."
118
- Invoke-Expression $baseDockerBuildCmd
119
- Write-Host " = BUILD: Finished building all image"
122
+ Invoke-Expression $dockerBuildCmd
120
123
}
124
+ Write-Host " = BUILD: Finished building ${current} "
121
125
122
126
if ($lastExitCode -ne 0 ) {
123
127
exit $lastExitCode
@@ -153,49 +157,53 @@ function Test-Image {
153
157
}
154
158
155
159
if ($target -eq " test" ) {
156
- Write-Host " = TEST: Starting test harness"
157
-
158
- # Only fail the run afterwards in case of any test failures
159
- $testFailed = $false
160
- $mod = Get-InstalledModule - Name Pester - MinimumVersion 5.3 .0 - MaximumVersion 5.3 .3 - ErrorAction SilentlyContinue
161
- if ($null -eq $mod ) {
162
- Write-Host " = TEST: Pester 5.3.x not found: installing..."
163
- $module = " c:\Program Files\WindowsPowerShell\Modules\Pester"
164
- if (Test-Path $module ) {
165
- takeown / F $module / A / R
166
- icacls $module / reset
167
- icacls $module / grant Administrators:' F' / inheritance:d / T
168
- Remove-Item - Path $module - Recurse - Force - Confirm:$false
160
+ if ($DryRun ) {
161
+ Write-Host " = TEST: (dry-run) test harness"
162
+ } else {
163
+ Write-Host " = TEST: Starting test harness"
164
+
165
+ # Only fail the run afterwards in case of any test failures
166
+ $testFailed = $false
167
+ $mod = Get-InstalledModule - Name Pester - MinimumVersion 5.3 .0 - MaximumVersion 5.3 .3 - ErrorAction SilentlyContinue
168
+ if ($null -eq $mod ) {
169
+ Write-Host " = TEST: Pester 5.3.x not found: installing..."
170
+ $module = " c:\Program Files\WindowsPowerShell\Modules\Pester"
171
+ if (Test-Path $module ) {
172
+ takeown / F $module / A / R
173
+ icacls $module / reset
174
+ icacls $module / grant Administrators:' F' / inheritance:d / T
175
+ Remove-Item - Path $module - Recurse - Force - Confirm:$false
176
+ }
177
+ Install-Module - Force - Name Pester - MaximumVersion 5.3 .3
169
178
}
170
- Install-Module - Force - Name Pester - MaximumVersion 5.3 .3
171
- }
172
179
173
- Import-Module Pester
174
- Write-Host " = TEST: Setting up Pester environment..."
175
- $configuration = [PesterConfiguration ]::Default
176
- $configuration.Run.PassThru = $true
177
- $configuration.Run.Path = ' .\tests'
178
- $configuration.Run.Exit = $true
179
- $configuration.TestResult.Enabled = $true
180
- $configuration.TestResult.OutputFormat = ' JUnitXml'
181
- $configuration.Output.Verbosity = ' Diagnostic'
182
- $configuration.CodeCoverage.Enabled = $false
183
-
184
- if (! [System.String ]::IsNullOrWhiteSpace($Build ) -and $builds.ContainsKey ($Build )) {
185
- Test-Image $Build
186
- } else {
187
- Write-Host " = TEST: Testing all images..."
188
- foreach ($image in $builds.Keys ) {
189
- Test-Image $image
180
+ Import-Module Pester
181
+ Write-Host " = TEST: Setting up Pester environment..."
182
+ $configuration = [PesterConfiguration ]::Default
183
+ $configuration.Run.PassThru = $true
184
+ $configuration.Run.Path = ' .\tests'
185
+ $configuration.Run.Exit = $true
186
+ $configuration.TestResult.Enabled = $true
187
+ $configuration.TestResult.OutputFormat = ' JUnitXml'
188
+ $configuration.Output.Verbosity = ' Diagnostic'
189
+ $configuration.CodeCoverage.Enabled = $false
190
+
191
+ if (! [System.String ]::IsNullOrWhiteSpace($Build ) -and $builds.ContainsKey ($Build )) {
192
+ Test-Image $Build
193
+ } else {
194
+ Write-Host " = TEST: Testing all images..."
195
+ foreach ($image in $builds.Keys ) {
196
+ Test-Image $image
197
+ }
190
198
}
191
- }
192
199
193
- # Fail if any test failures
194
- if ($testFailed -ne $false ) {
195
- Write-Error " Test stage failed!"
196
- exit 1
197
- } else {
198
- Write-Host " Test stage passed!"
200
+ # Fail if any test failures
201
+ if ($testFailed -ne $false ) {
202
+ Write-Error " Test stage failed!"
203
+ exit 1
204
+ } else {
205
+ Write-Host " Test stage passed!"
206
+ }
199
207
}
200
208
}
201
209
@@ -204,14 +212,18 @@ function Publish-Image {
204
212
[String ] $Build ,
205
213
[String ] $ImageName
206
214
)
207
- # foreach($tag in $builds[$ImageName]['Tags']) {
208
- # $fullImageName = '{0}/{1}:{2}' -f $Organization, $Repository, $tag
209
- # $cmd = "docker tag {0} {1}" -f $ImageName, $tag
210
- Write-Host " = PUBLISH: Tagging $Build => full name = $ImageName "
211
- docker tag " $Build " " $ImageName "
212
-
213
- Write-Host " = PUBLISH: Publishing $ImageName ..."
214
- docker push " $ImageName "
215
+ if ($DryRun ) {
216
+ Write-Host " = PUBLISH: (dry-run) docker tag then publish '$Build $ImageName '"
217
+ } else {
218
+ # foreach($tag in $builds[$ImageName]['Tags']) {
219
+ # $fullImageName = '{0}/{1}:{2}' -f $Organization, $Repository, $tag
220
+ # $cmd = "docker tag {0} {1}" -f $ImageName, $tag
221
+ Write-Host " = PUBLISH: Tagging $Build => full name = $ImageName "
222
+ docker tag " $Build " " $ImageName "
223
+
224
+ Write-Host " = PUBLISH: Publishing $ImageName ..."
225
+ docker push " $ImageName "
226
+ }
215
227
}
216
228
217
229
0 commit comments