简体   繁体   中英

Azure Image Builder - How to Specify the VM Image Version

It appears the default three part version is some sort of timestamp. I would like to be able to specify the version number when I generate the image versions. I see only a mention of the version format in a troubleshooting guide but no specifics on how to set it.

eg The image version name should follow Major(int).Minor(int).Patch(int) format, for eg: 1.0.0, 2018.12.1 etc.

在此处输入图像描述

I setup the distributor with:

  $distributorObjectParameters = @{
    SharedImageDistributor = $true
    GalleryImageId         = $galleryImageId
    ReplicationRegion      = $Location
    ArtifactTag            = $tags
    RunOutputName          = $imageTemplateName
    ExcludeFromLatest      = $false
  }
  $distributorObject = New-AzImageBuilderDistributorObject @distributorObjectParameters

Then create the template with:

  $templateParameters = @{
    ImageTemplateName      = $imageTemplateName
    ResourceGroupName      = $imageResourceGroup
    Source                 = $sourceObject
    Distribute             = $distributorObject
    Customize              = $customizerCollection
    Location               = 'East US 2'
    UserAssignedIdentityId = $identityResourceId
    BuildTimeoutInMinute   = $buildTimeoutInMinute
  }
  New-AzImageBuilderTemplate @templateParameters

Is there a parameter that I have overlooked for setting the version value?

The following answer was provided by someone from Microsoft on GitHub. https://github.com/MicrosoftDocs/azure-docs/issues/89180#issuecomment-1063218290

The parameter named galleryImageId for the distributor sets the version. The parameter can be specified as one of two formats:

  • Automatic versioning - The format is: /subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.Compute/galleries/<sharedImageGalleryName>/images/<imageGalleryName>

  • Explicit versioning - The format is: /subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.Compute/galleries/<sharedImageGalleryName>/images/<imageGalleryName>/versions/<version - for example: 1.1.1>

For reference: https://learn.microsoft.com/en-us/azure/virtual-machines/linux/image-builder-json#distribute-sharedimage

To test it out, I modified my distributor setup with:

  $distributorObjectParameters = @{
    SharedImageDistributor = $true
    GalleryImageId         = "$($galleryImageId)/versions/0.0.1"
    ReplicationRegion      = $Location
    ArtifactTag            = $tags
    RunOutputName          = $imageTemplateName
    ExcludeFromLatest      = $false
  }
  $distributorObject = New-AzImageBuilderDistributorObject @distributorObjectParameter

and got the following result: 在此处输入图像描述

I don't think you can have that option from Azure. In our projects, we compute versions ourselves with bash and az-cli .

IMAGE_VERSIONS=$(az sig image-version list --gallery-image-definition "${image_definition_name}" --gallery-name "${image_gallery_name}" -g "${ARM_RESOURCE_GROUP}")
if [[ "${IMAGE_VERSIONS}" == "[]" ]]; then
    DESTINATION_IMAGE_VERSION="1.0.0"
else
    DESTINATION_IMAGE_VERSION=$(echo "${IMAGE_VERSIONS}" | grep -i "versions/" | tail -n 1 | rev | cut -d '/' -f1 | cut -d '"' -f2 | rev)
fi
DESTINATION_IMAGE_VERSION=$(echo "${DESTINATION_IMAGE_VERSION}" | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}')
echo $DESTINATION_IMAGE_VERSION

We instantiate the initial version to 1.0.0 (for the first time) & once set, we just increment in next build iterations..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM