diff --git a/.pipelines/templates/.builder-release-template-windows.yaml b/.pipelines/templates/.builder-release-template-windows.yaml index 5da7c54e949..3ca2870d869 100644 --- a/.pipelines/templates/.builder-release-template-windows.yaml +++ b/.pipelines/templates/.builder-release-template-windows.yaml @@ -220,47 +220,10 @@ steps: SIG_GALLERY_NAME: $(SIG_GALLERY_NAME) SIG_IMAGE_VERSION: $(SIG_IMAGE_VERSION) - # SA_NAME: Temporary storage account name - # IMPORTED_IMAGE_NAME: Build output for windowsVhdMode is SIG. Packer does not support building a SIG from raw - # VHD blob directly. Will use this as an intermediate sig to import from raw VHD url. - # Can be deleted after building. - # SIG_IMAGE_NAME: Packer-generated SIG image for windowsVhdMode. (Gen 2 included) If SIG_FOR_PRODUCTION = True - # This image should be deleted. Otherwise, we keep it. - # Used to define the IMAGE_NAME below. - # IMAGE_NAME: Managed image created by packer: ManagedImageName in log. No longer used. - # Can be cleaned up in this step. - - task: AzureCLI@2 - inputs: - azureSubscription: $(VHD_ARM_SERVICE_CONNECTION) - scriptType: bash - scriptLocation: inlineScript - inlineScript: | - set -e - - export PKR_RG_NAME="$(cat packer-output | grep -a "ResourceGroupName" | cut -d "'" -f 2 | head -1)" - export SA_NAME="$(cat packer-output | grep -a "storage name:" | cut -d " " -f 3)" - export IMPORTED_IMAGE_NAME="$(cat vhdbuilder/packer/settings.json | grep "imported_image_name" | awk -F':' '{print $2}' | awk -F'"' '{print $2}')" - export SIG_IMAGE_NAME="$(cat vhdbuilder/packer/settings.json | grep "sig_image_name" | awk -F':' '{print $2}' | awk -F'"' '{print $2}')" - export IMAGE_NAME="$(cat packer-output | grep -a "ManagedImageName:" | cut -d " " -f 2)" - - ./vhdbuilder/packer/cleanup.sh - displayName: Clean Up Packer Generated Resources - condition: always() - env: - MODE: $(MODE) - DRY_RUN: $( DRY_RUN ) - VNET_RESOURCE_GROUP_NAME: $(VNET_RESOURCE_GROUP_NAME) - TEST_VM_RESOURCE_GROUP_NAME: $(TEST_VM_RESOURCE_GROUP_NAME) - SKIP_EXTENSION_CHECK: ${{ parameters.skipExtensionCheck }} - WINDOWS_SKU: ${{ parameters.windowsSku }} - SIG_GALLERY_NAME: $(SIG_GALLERY_NAME) - SIG_IMAGE_VERSION: $(SIG_IMAGE_VERSION) - SIG_FOR_PRODUCTION: $(SIG_FOR_PRODUCTION) - OS_TYPE: "Windows" - # Set VHD_NAME and SKU_NAME which will be published. # Note: use -a to grep OS_DISK_SAS (packer-output should be read as a binary file in Linux) - # Perform this step only if we want to publish the VHD: Gen 1 or Gen 2 and the built sig is for production. + # we always generate these artifacts - sometimes they are used by downstream pipelines even when + # we are not publishing the image to production. - task: AzureCLI@2 inputs: azureSubscription: $(VHD_ARM_SERVICE_CONNECTION) @@ -273,14 +236,14 @@ steps: export captured_sig_version="$(cat vhdbuilder/packer/settings.json | grep "captured_sig_version" | awk -F':' '{print $2}' | awk -F'"' '{print $2}')" [ -n "${captured_sig_version}" ] && export VHD_NAME="${captured_sig_version}.vhd"; else - export OS_DISK_SAS="$(cat packer-output | grep -a "OSDiskUriReadOnlySas:" | cut -d " " -f 2)"; - export VHD_NAME="$(echo $OS_DISK_SAS | cut -d "/" -f 8 | cut -d "?" -f 1)"; + export captured_sig_version="$(cat vhdbuilder/packer/settings.json | grep "captured_sig_version" | awk -F':' '{print $2}' | awk -F'"' '{print $2}')" + [ -n "${captured_sig_version}" ] && export VHD_NAME="${captured_sig_version}.vhd"; + export STORAGE_ACCT_BLOB_URL="$(echo $OS_DISK_SAS | cut -d "/" -f 1-7)"; fi export SKU_NAME="windows-$WINDOWS_SKU"; make -f packer.mk generate-publishing-info displayName: Getting Shared Access Signature URI - condition: and(succeeded(), eq(variables.DRY_RUN, 'False'), eq(variables.SIG_FOR_PRODUCTION, 'True')) env: SUBSCRIPTION_ID: $(AZURE_PROD_SUBSCRIPTION_ID) STORAGE_ACCT_BLOB_URL: $(STORAGE_ACCT_BLOB_URL) @@ -295,9 +258,45 @@ steps: OS_TYPE: "Windows" WINDOWS_SKU: ${{ parameters.windowsSku }} - # Will be stepped in if the sig is for production - task: PublishPipelineArtifact@1 inputs: artifactName: 'publishing-info-${{ parameters.artifactName }}' targetPath: 'vhd-publishing-info.json' - condition: and(succeeded(), eq(variables.DRY_RUN, 'False'), eq(variables.SIG_FOR_PRODUCTION, 'True')) + + # SA_NAME: Temporary storage account name + # IMPORTED_IMAGE_NAME: Build output for windowsVhdMode is SIG. Packer does not support building a SIG from raw + # VHD blob directly. Will use this as an intermediate sig to import from raw VHD url. + # Can be deleted after building. + # SIG_IMAGE_NAME: Packer-generated SIG image for windowsVhdMode. (Gen 2 included) If SIG_FOR_PRODUCTION = True + # This image should be deleted. Otherwise, we keep it. + # Used to define the IMAGE_NAME below. + # IMAGE_NAME: Managed image created by packer: ManagedImageName in log. No longer used. + # Can be cleaned up in this step. + - task: AzureCLI@2 + inputs: + azureSubscription: $(VHD_ARM_SERVICE_CONNECTION) + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -e + + export PKR_RG_NAME="$(cat packer-output | grep -a "ResourceGroupName" | cut -d "'" -f 2 | head -1)" + export SA_NAME="$(cat packer-output | grep -a "storage name:" | cut -d " " -f 3)" + export IMPORTED_IMAGE_NAME="$(cat vhdbuilder/packer/settings.json | grep "imported_image_name" | awk -F':' '{print $2}' | awk -F'"' '{print $2}')" + export SIG_IMAGE_NAME="$(cat vhdbuilder/packer/settings.json | grep "sig_image_name" | awk -F':' '{print $2}' | awk -F'"' '{print $2}')" + export IMAGE_NAME="$(cat packer-output | grep -a "ManagedImageName:" | cut -d " " -f 2)" + + ./vhdbuilder/packer/cleanup.sh + displayName: Clean Up Packer Generated Resources + condition: always() + env: + MODE: $(MODE) + DRY_RUN: $( DRY_RUN ) + VNET_RESOURCE_GROUP_NAME: $(VNET_RESOURCE_GROUP_NAME) + TEST_VM_RESOURCE_GROUP_NAME: $(TEST_VM_RESOURCE_GROUP_NAME) + SKIP_EXTENSION_CHECK: ${{ parameters.skipExtensionCheck }} + WINDOWS_SKU: ${{ parameters.windowsSku }} + SIG_GALLERY_NAME: $(SIG_GALLERY_NAME) + SIG_IMAGE_VERSION: $(SIG_IMAGE_VERSION) + SIG_FOR_PRODUCTION: $(SIG_FOR_PRODUCTION) + OS_TYPE: "Windows"