Build Machine Image task

Azure Pipelines

Use this task in a build or release pipeline to build a machine image using Packer. This image can be used for Azure Virtual machine scale set deployment.

YAML snippet

# Build machine image
# Build a machine image using Packer, which may be used for Azure Virtual machine scale set deployment
- task: PackerBuild@1
    #templateType: 'builtin' # Options: builtin, custom
    #customTemplateLocation: # Required when templateType == Custom
    #customTemplateParameters: '{}' # Optional
    #isManagedImage: true 
    #managedImageName: # Required when isManagedImage == True
    #baseImageSource: 'default' # Options: default, customVhd
    #baseImage: 'MicrosoftWindowsServer:WindowsServer:2012-R2-Datacenter:windows' # Required when baseImageSource == Default# Options: microsoftWindowsServer:WindowsServer:2012-R2-Datacenter:Windows, microsoftWindowsServer:WindowsServer:2016-Datacenter:Windows, microsoftWindowsServer:WindowsServer:2012-Datacenter:Windows, microsoftWindowsServer:WindowsServer:2008-R2-SP1:Windows, canonical:UbuntuServer:14.04.4-LTS:Linux, canonical:UbuntuServer:16.04-LTS:Linux, redHat:RHEL:7.2:Linux, redHat:RHEL:6.8:Linux, openLogic:CentOS:7.2:Linux, openLogic:CentOS:6.8:Linux, credativ:Debian:8:Linux, credativ:Debian:7:Linux, sUSE:OpenSUSE-Leap:42.2:Linux, sUSE:SLES:12-SP2:Linux, sUSE:SLES:11-SP4:Linux
    #customImageUrl: # Required when baseImageSource == CustomVhd
    #customImageOSType: 'windows' # Required when baseImageSource == CustomVhd# Options: windows, linux
    #deployScriptArguments: # Optional
    #additionalBuilderParameters: '{vm_size:Standard_D3_v2}' # Optional
    #skipTempFileCleanupDuringVMDeprovision: true # Optional
    #packerVersion: # Optional
    #imageUri: # Optional
    #imageId: # Optional


Packer template(Required) Select whether you want the task to auto generate Packer template or use custom template provided by you.
Packer template location(Required) Path to a custom user-provided template.
Template parameters(Optional) Specify parameters which will be passed to Packer for building custom template. This should map to "variables" section in your custom template. E.g. if the template has a variable named "drop-location", then add a parameter here with name "drop-location" and a value which you want to use. You can link the value to a release variable as well. To view/edit the additional parameters in a grid, click on "…" next to text box.
Azure subscription(Required) Select the Azure Resource Manager subscription for baking and storing the machine image.
Storage location(Required) Location for storing the built machine image. This location will also be used to create a temporary VM for the purpose of building image.
Storage account(Required) Storage account for storing the built machine image. This storage account must be pre-existing in the location selected.
Resource group(Required) Azure Resource group that contains the selected storage account.
Base image source(Required) Select the source of base image. You can either choose from a curated gallery of OS images or provide url of your custom image.
Base image(Required) Choose from curated list of OS images. This will be used for installing pre-requisite(s) and application(s) before capturing machine image.
Base image URL(Required) Specify url of base image. This will be used for installing pre-requisite(s) and application(s) before capturing machine image.
Base image OS(Required) undefined
Deployment Package(Required) Specify the path for deployment package directory relative to $(System.DefaultWorkingDirectory). Supports minimatch pattern. Example path: FrontendWebApp//GalleryApp
Deployment script(Required) Specify the relative path to powershell script(for Windows) or shell script(for Linux) which deploys the package. This script should be contained in the package path selected above. Supports minimatch pattern. Example path: deploy//scripts/windows/deploy.ps1
Deployment script arguments(Optional) Specify the arguments to be passed to deployment script.
Additional Builder parameters(Optional) In auto generated Packer template mode the task creates a Packer template with an Azure builder. This builder is used to generate a machine image. You can add keys to the Azure builder to customize the generated Packer template. For example setting ssh_tty=true in case you are using a CentOS base image and you need to have a tty to run sudo.
To view/edit the additional parameters in a grid, click on “…” next to text box.
Skip temporary file cleanup during deprovision(Optional) During deprovisioning of VM, skip clean-up of temporary files uploaded to VM. Refer here
Image URL(Optional) Provide a name for the output variable which will store generated machine image url.
Control options

Open source

This task is open source on GitHub. Feedback and contributions are welcome.