@@ -193,7 +193,17 @@ extends:
193193 docker pull mcr.microsoft.com/azuremonitor/containerinsights/cidev/prometheus-collector/images:buildx-stable-1
194194 docker buildx create --name dockerbuilder --driver docker-container --driver-opt image=mcr.microsoft.com/azuremonitor/containerinsights/cidev/prometheus-collector/images:buildx-stable-1 --use
195195 docker buildx inspect --bootstrap
196+ # Determine if we should push to ACR
197+ # Push when: NOT a PR, OR when PR is from specific branches (zane/ci-agent-auto-deploy or branches containing 'run-e2e')
198+ SHOULD_PUSH="false"
196199 if [ "$(Build.Reason)" != "PullRequest" ]; then
200+ SHOULD_PUSH="true"
201+ elif [[ "$(System.PullRequest.SourceBranch)" == "zane/ci-agent-auto-deploy" ]] || [[ "$(System.PullRequest.SourceBranch)" == *"run-e2e"* ]]; then
202+ SHOULD_PUSH="true"
203+ echo "PR from branch $(System.PullRequest.SourceBranch) - will push image to ACR for E2E testing"
204+ fi
205+
206+ if [ "$SHOULD_PUSH" == "true" ]; then
197207 docker buildx build --platform $(BUILD_PLATFORMS) --tag ${{ variables.repoImageName }}:$(linuxImagetag) -f kubernetes/linux/Dockerfile.multiarch --metadata-file $(Build.ArtifactStagingDirectory)/linux/metadata.json --build-arg IMAGE_TAG=$(linuxTelemetryTag) --build-arg GOLANG_BASE_IMAGE=$(GOLANG_BASE_IMAGE) --build-arg CI_BASE_IMAGE=$(CI_BASE_IMAGE) --push --provenance=false .
198208 echo "##vso[task.logissue type=warning]Linux image built with tag: ${{ variables.repoImageName }}:$(linuxImagetag)"
199209 docker pull ${{ variables.repoImageName }}:$(linuxImagetag)
@@ -551,7 +561,16 @@ extends:
551561 inputs :
552562 targetType : ' inline'
553563 script : |
564+ # Push when: NOT a PR, OR when PR is from specific branches (zane/ci-agent-auto-deploy or branches containing 'run-e2e')
565+ $shouldPush = $false
554566 if ("$(Build.Reason)" -ne "PullRequest") {
567+ $shouldPush = $true
568+ } elseif ("$(System.PullRequest.SourceBranch)" -eq "zane/ci-agent-auto-deploy" -or "$(System.PullRequest.SourceBranch)" -like "*run-e2e*") {
569+ $shouldPush = $true
570+ Write-Host "PR from branch $(System.PullRequest.SourceBranch) - will push image to ACR for E2E testing"
571+ }
572+
573+ if ($shouldPush) {
555574 docker push ${{ variables.repoImageName }}:$(windowsImageTag)-$(windows2019BaseImageVersion)
556575 }
557576 - task : CodeQL3000Finalize@0
@@ -759,7 +778,16 @@ extends:
759778 inputs :
760779 targetType : ' inline'
761780 script : |
781+ # Push when: NOT a PR, OR when PR is from specific branches (zane/ci-agent-auto-deploy or branches containing 'run-e2e')
782+ $shouldPush = $false
762783 if ("$(Build.Reason)" -ne "PullRequest") {
784+ $shouldPush = $true
785+ } elseif ("$(System.PullRequest.SourceBranch)" -eq "zane/ci-agent-auto-deploy" -or "$(System.PullRequest.SourceBranch)" -like "*run-e2e*") {
786+ $shouldPush = $true
787+ Write-Host "PR from branch $(System.PullRequest.SourceBranch) - will push image to ACR for E2E testing"
788+ }
789+
790+ if ($shouldPush) {
763791 docker push ${{ variables.repoImageName }}:$(windowsImageTag)-$(windows2022BaseImageVersion)
764792 }
765793 - task : CodeQL3000Finalize@0
@@ -800,7 +828,16 @@ extends:
800828 az account set -s ${{ variables.subscription }}
801829 az acr login -n ${{ variables.containerRegistry }}
802830 @{"image.name"="${{ variables.repoImageName }}:$(windowsImageTag)"} | ConvertTo-Json -Compress | Out-File -Encoding ascii $(Build.ArtifactStagingDirectory)/windows/metadata.json
831+ # Push when: NOT a PR, OR when PR is from specific branches (zane/ci-agent-auto-deploy or branches containing 'run-e2e')
832+ $shouldPush = $false
803833 if ("$(Build.Reason)" -ne "PullRequest") {
834+ $shouldPush = $true
835+ } elseif ("$(System.PullRequest.SourceBranch)" -eq "zane/ci-agent-auto-deploy" -or "$(System.PullRequest.SourceBranch)" -like "*run-e2e*") {
836+ $shouldPush = $true
837+ Write-Host "PR from branch $(System.PullRequest.SourceBranch) - will push multi-arch image to ACR for E2E testing"
838+ }
839+
840+ if ($shouldPush) {
804841 docker manifest create ${{ variables.repoImageName }}:$(windowsImageTag) ${{ variables.repoImageName }}:$(windowsImageTag)-$(windows2019BaseImageVersion) ${{ variables.repoImageName }}:$(windowsImageTag)-$(windows2022BaseImageVersion)
805842 docker manifest push ${{ variables.repoImageName }}:$(windowsImageTag)
806843 Write-Host "##vso[task.logissue type=warning]Windows image built with tag: ${{ variables.repoImageName }}:$(windowsImageTag)"
0 commit comments