Skip to content

Commit a533587

Browse files
committed
add WhatIf parameter to the pipeline
1 parent 487e879 commit a533587

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

.pipelines/PowerShell-Docker-Image-Build-Official.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ parameters:
55
default: 'v7.4.0-preview.5'
66
- name: 'releaseChannel'
77
default: 'preview'
8+
- name: 'whatIf'
9+
displayName: 'Skip publishing to MCR, but show what would get published and attached'
10+
type: boolean
11+
default: false
812
variables:
913
- name: POWERSHELL_TELEMETRY_OPTOUT
1014
value: 1
@@ -16,6 +20,8 @@ variables:
1620
value: ${{ parameters.releaseChannel }}
1721
- name: releaseChannelPath
1822
value: ''
23+
- name: whatIf
24+
value: ${{ parameters.whatIf }}
1925
- name: runCodesignValidationInjection
2026
value: false
2127
- name: DisableDockerDetector
@@ -129,6 +135,7 @@ extends:
129135
$info = @{}
130136
$info.Add("channel", $env:RELEASECHANNEL)
131137
$info.Add("releaseVersionTag", $env:RELEASEVERSIONTAG)
138+
$info.Add("whatIf", $env:WHATIF)
132139
$info | ConvertTo-Json | Out-File -Encoding utf8NoBOM -FilePath ./BuildInfo.json
133140
displayName: 'Write build info to file'
134141
- task: CopyFiles@2

.pipelines/PowerShell-Docker-Image-Release-Official.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ extends:
6363
$currentChannel = $($buildMetadata.channel)
6464
$currentVersion = $($buildMetadata.releaseVersionTag)
6565
$finalVersion = $currentVersion.Trim("v")
66-
Write-Verbose -Verbose "version: $finalVersion and channel: $currentChannel"
66+
$whatIfSwitch = $($buildMetadata.whatIf)
67+
Write-Verbose -Verbose "version: $finalVersion and channel: $currentChannel and whatIf: $whatIf"
6768
Write-Host "##vso[task.setvariable variable=channel;isOutput=true]$currentChannel"
6869
Write-Host "##vso[task.setvariable variable=version;isOutput=true]$finalVersion"
70+
Write-Host "##vso[task.setvariable variable=whatIf;isOutput=true]$whatIfSwitch"
6971
displayName: 'Get channel from buildInfo.json'
7072
name: setChannelStep
7173
- job: DownloadImageArtifactFromBuild
@@ -275,6 +277,8 @@ extends:
275277
value: $[ stageDependencies.GetBuildArtifacts.DownloadMetaArtifactFromBuild.outputs['setChannelStep.channel'] ]
276278
- name: version
277279
value: $[ stageDependencies.GetBuildArtifacts.DownloadMetaArtifactFromBuild.outputs['setChannelStep.version'] ]
280+
- name: whatIf
281+
value: $[ stageDependencies.GetBuildArtifacts.DownloadMetaArtifactFromBuild.outputs['setChannelStep.whatIf'] ]
278282
pool:
279283
timeoutInMinutes: 30
280284
type: windows
@@ -299,6 +303,7 @@ extends:
299303
$pathToImageMetadataFile = Join-Path -Path $pathToParametersFolder -ChildPath 'ImageMetadata.json'
300304
$pathToChannelJsonFile = Join-Path -Path $pathToParametersFolder -ChildPath 'ChannelInfo.json'
301305
$currentChannel = '$(channel)'
306+
$currentWhatIfSwitch = '$(whatIf)'
302307
303308
$channelHash = @{channel=$currentChannel}
304309
$channelHash | ConvertTo-Json | Out-File $pathToChannelJsonFile

EV2Specs/ServiceGroupRoot/Shell/Run/Run.ps1

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ try {
123123
Write-Verbose -Verbose "Getting channel info"
124124
$channelJsonFileContent = Get-Content -Path $pathToChannelJson | ConvertFrom-Json
125125
$channel = $channelJsonFileContent.channel
126+
$whatIf = $channelJsonFileContent.whatIf
126127

127128
Write-Verbose -Verbose "Getting image info"
128129
$imgJsonFileContent = Get-Content -Path $pathToImgMetadataJson | ConvertFrom-Json
@@ -169,18 +170,38 @@ try {
169170
# Import (old) image by digest from MCR into our ACR
170171
$mcrImageNameDigest = "mcr.microsoft.com/powershell@$imageDigest"
171172
$acrEOLImageTag = "$tag-EOL"
172-
az acr import --name $env:DESTINATION_ACR_NAME --source $mcrImageNameDigest --image $acrEOLImageTag
173+
if (!$whatIf)
174+
{
175+
az acr import --name $env:DESTINATION_ACR_NAME --source $mcrImageNameDigest --image $acrEOLImageTag
176+
}
177+
else {
178+
Write-Verbose -Verbose "az acr import --name $env:DESTINATION_ACR_NAME --source $mcrImageNameDigest --image $acrEOLImageTag"
179+
}
173180

174181
# Attach lifecycle annotation, which will eventually get synced to MCR
175182
$acrImageNameDigest = "$env:DESTINATION_ACR_NAME.azurecr.io/public/powershell@$imageDigest"
176-
oras attach --artifact-type "application/vnd.microsoft.artifact.lifecycle" --annotation "vnd.microsoft.artifact.lifecycle.end-of-life.date=$endOfLifeDate" $acrImageNameDigest
183+
if (!$whatIf)
184+
{
185+
oras attach --artifact-type "application/vnd.microsoft.artifact.lifecycle" --annotation "vnd.microsoft.artifact.lifecycle.end-of-life.date=$endOfLifeDate" $acrImageNameDigest
186+
}
187+
else {
188+
Write-Verbose -Verbose "oras attach --artifact-type `"application/vnd.microsoft.artifact.lifecycle`" --annotation `"vnd.microsoft.artifact.lifecycle.end-of-life.date=$endOfLifeDate`" $acrImageNameDigest"
189+
}
190+
177191
}
178192

179193
# Need to push image for each tag
180194
$destination_image_full_name = "$env:DESTINATION_ACR_NAME.azurecr.io/public/powershell:${tag}"
181195
Write-Verbose -Verbose "dest img full name: $destination_image_full_name"
182196
Write-Verbose -Verbose "Pushing file $tarballFilePath to $destination_image_full_name"
183-
./crane push $tarballFilePath $destination_image_full_name
197+
if (!$whatIf)
198+
{
199+
./crane push $tarballFilePath $destination_image_full_name
200+
}
201+
else {
202+
Write-Verbose "./crane push $tarballFilePath $destination_image_full_name"
203+
}
204+
184205
Write-Verbose -Verbose "done pushing for tag: $tag"
185206
}
186207
}

0 commit comments

Comments
 (0)