Automation x2: How to automate Azure DevOps pipelines with Advanced Installer PowerShell automation

Written by Ciprian Burca · November 25th, 2020

Working with Azure DevOps pipelines can be a tedious task, especially if you have to perform updates on complex pipelines or make the necessary configurations to each of them in a short amount of time.

To be more efficient and avoid time-consuming tasks, Advanced Installer built a complete PowerShell interface to leverage your project’s performance and give you a break from endless chores.

In this two step tutorial, I will show you how to enable and use the PowerShell interface directly from an Azure DevOps pipeline.

Enable PowerShell support

The first thing we need to do is to deploy Advanced Installer on the build agent. In order to achieve that, we will use the Advanced Installer Tool task. Add it to your pipeline.

TipIf you want to learn more about the Advanced Installer DevOps tasks I recommend you to read this article:Which Azure DevOps task should I choose?

In the Pipeline page, go to the task view page, and check “Enable PowerShell Automation option”.

NoteThe minimum required Advanced Installer version for this feature to work is 16.1.

For those who prefer to have the code, here's YAML (Yet Another Markup Language):

steps:
- task: caphyon.AdvancedInstallerTool.Caphyon.AdvancedInstaller.Tool.Advanced
InstallerTool@1
  displayName: 'Use Advanced Installer 16.1'
  inputs:
	advinstVersion: 16.1
	advinstLicense: '$(advancedinstaller.license)'
	advinstEnableCom: true

That's it. You are good to go.

Adding the PowerShell Script

As a demo, I have used a PowerShell task with the following inline script which increases the “ProductVersion” and builds the project.

PowerShell:

# Load the AIP project from checkout location
$aipPath = join-path $env:BUILD_SOURCESDIRECTORY "Simple.aip";
Write-Host "AIP: $aipPath";

$advinst = new-object -com advancedinstaller;
$project = $advinst.LoadProject($aipPath);
$productDetails = $project.ProductDetails;

# Bump the ProductVersion
$productDetails.Version = "1.2.0";
Write-Host "Version: $productDetails.Version";

# Build the project
$project.Build();

YAML:

  steps:
- powershell: |
   # Load the AIP project from checkout location
   $aipPath = join-path $env:BUILD_SOURCESDIRECTORY "Simple.aip";
   Write-Host "AIP: $aipPath";
   
   $advinst = new-object -com advancedinstaller;
   $project = $advinst.LoadProject($aipPath);
   $productDetails = $project.ProductDetails;
   
   # Bump the ProductVersion
   $productDetails.Version = "1.2.0";
   Write-Host "Version: $productDetails.Version";
   
   # Build the project
   $project.Build();
   
  displayName: 'Build AIP Project'

ImportantIf you prefer hosting Azure DevOps in house, this tutorial would be helpful for you too.However there is a prerequisite that should be met : because Advanced Installer will register a COM object during the pipeline, the build agent needs to run with elevated privileges.

In this short tutorial, you've learned that working with PowerShell Automation is a straightforward and painless process when configuring numerous Azure DevOps pipelines.

I hope you found it useful, and I would love to hear from you about your Powershell automation experience with Azure DevOps pipelines.

Comments: