This script creates ACI container instance(s) which run the Azure DevOps (formerly VSTS) Agent, alongside with the requested PowerShell modules, json2hcl and Terraform to enable Azure resource build automation from Azure DevOps CI/CD pipelines.
This script is used as a wrapper of the container configuration script ("Install-VstsAgentOnWindowsServerCoreContainer.ps1") to create ACI container instance(s) which run the Azure DevOps Agent, alongside with the requested PowerShell modules, json2hcl and Terraform to enable Azure resource build automation from Azure DevOps CI/CD pipelines.
It copies the container configuration script to a publicly available storage container of the requested Storage Account, it creates a new Resource Group (if one doesn't exist with the provided name), removes any pre-existing ACI containers with the same name, within the same Resource Group, then creates new ACI container instance(s) based on the provided names and invokes the container configuration script inside the container(s).
This script is designed and tested to be run from Azure Cloud Shell.
Prerequisites:
- Azure Subscription, with an existing Storage Account
- You need to have admin rights :
- to create a storage container within the already existing Storage Account - OR - you need to have a storage container which has its public access type configured to the type of "Blob",
- to create a new Resource Group - OR - an existing Resource Group for the Azure Container Instances,
- to create resources in the selected Resource Group.
- Azure DevOps account with the requested Agent Pool has to exist.
- Permission in the Azure DevOps account to add Agents to the chosen Agent Pool.
- A PAT token.
SubscriptionName
: Name of the Azure Subscription.ResourceGroupName
: Name of the Resource Group.ContainerName
: Name of the ACI container(s).ReplaceExistingContainer
: Switch to replace existing container(s) with the same name(s) provided.MemoryInGB
: Amount of memory in GBs.Cpu
: Number of CPU cores.Location
: Region of the Azure resources.StorageAccountName
: Name of the Storage Account to upload the script file to, which is then invoke by this wrapper.StorageContainerName
: Name of the storage container to upload the script file to be invoked by this wrapper.ScriptPublicUrl
: Publicly available URL of the internal script file to be invoked by this wrapper. This can be used optionally, instead of defining the Storage Account name. You need to make the internal script available on this URL as a prerequisite.ScriptFileName
: Name of the script file to invoke by this wrapper.VSTSAccountName
: Name of the Azure DevOps account - formerly Visual Studio Team Services (VSTS) account, e.g.https://<Azure DevOps Account Name>.visualstudio.com
- OR -https://dev.azure.com/<Azure DevOps Account Name>/
PATToken
: PAT token generated by the user who is configuring the container to be used by Azure DevOps.PoolName
: Name of the Agent pool. It defaults to the "Default" pool when not defined.RequiredPowerShellModules
: List of the required PowerShell modules, e.g. Az, AzureAD, PesterContainerImage
: Fully qualified name of the container image, optionally including tags.AcrPassword
: Access password to the Azure Container Registry (ACR).InstallAzureCli
: Switch to define whether or not you want to install the Azure CLI on your container.InstallPowerShellCore
: Switch to define whether or not you want to install Azure PowerShell Core on your container.UseChocolatey
: Switch to define whether or not Chocolatey should be used to install the supported components
Initialize-VstsAgentOnWindowsServerCoreContainer.ps1 -SubscriptionName "<subscription name>" -ResourceGroupName "<resource group name>" -ContainerName "<container 1 name>", "<container 2 name>" -Location "<azure region>" -StorageAccountName "<storage account name>" -VSTSAccountName "<azure devops account name>" -PATToken "<PAT token>"
This uploads the container configuration script to the default "publicvstsscript" storage container of the requested Storage Account and then creates 2 Azure Container Instances, with the default settings (Default Agent Pool 1 GB RAM, 1 CPU core, PowerShell modules installed: "Az", "AzureAD", "Pester").
Initialize-VstsAgentOnWindowsServerCoreContainer.ps1 -SubscriptionName "<subscription name>" -ResourceGroupName "<resource group name>" -ContainerName "<container 1 name>", "<container 2 name>" -Location "<azure region>" -VSTSAccountName "<azure devops account name>" -PATToken "<PAT token>"
This downloads the container configuration script directly from its default location on GitHub, and then creates 2 Azure Container Instances, with the default settings (Default Agent Pool 1 GB RAM, 1 CPU core, PowerShell modules installed: "Az", "AzureAD", "Pester").
Initialize-VstsAgentOnWindowsServerCoreContainer.ps1 -SubscriptionName "<subscription name>" -ResourceGroupName "<resource group name>" -ContainerName "<container 1 name>", "<container 2 name>" -Location "<azure region>" -VSTSAccountName "<azure devops account name>" -PATToken "<PAT token>" -ScriptPublicUrl "<public URL of the internal config script>"
This downloads the container configuration script directly from the provided location (this can be anything, e.g. GitHub, a public Storage Account, or any publicly available URL), and then creates 2 Azure Container Instances, with the default settings (Default Agent Pool 1 GB RAM, 1 CPU core, PowerShell modules installed: "Az", "AzureAD", "Pester").
Initialize-VstsAgentOnWindowsServerCoreContainer.ps1 -SubscriptionName "<subscription name>" -ResourceGroupName "<resource group name>" -ContainerName "<container 1 name>", "<container 2 name>" -Location "<azure region>" -StorageAccountName "<storage account name>" -StorageContainerName "publicvstsscript" -MemoryInGB 1 -Cpu 1 -ScriptFileName "Install-VstsAgentOnWindowsServerCoreContainer.ps1" -VSTSAccountName "<Azure DevOps Account name>" -PATToken "<PAT token>" -PoolName "<Azure DevOps Agent Pool name>" -RequiredPowerShellModules "Az", "AzureAD", "Pester"
This installs 2 Azure Container Instances with all the possible values manually defined.
Initialize-VstsAgentOnWindowsServerCoreContainer.ps1 -SubscriptionName "<subscription name>" -ResourceGroupName "<resource group name>" -ContainerName "<container 1 name>", "<container 2 name>" -Location "<azure region 2>" -StorageAccountName "<storage account name>" -VSTSAccountName "<azure devops account name>" -PATToken "<PAT token>" -PoolName "<agent pool name>" -ReplaceExistingContainer
This removes any existing ACI containers with the provided names, then creates new ones with the requested values.
.\Initialize-VstsAgentOnWindowsServerCoreContainer.ps1 -SubscriptionName "<subscription name>" -ResourceGroupName "<resource group name>" -ContainerName "<container 1 name>", "<container 2 name>" -Location "<azure region>" -StorageAccountName "<storage account name>" -VSTSAccountName "<azure devops account name>" -PATToken "<PAT token>" -ContainerImage <myacr.azurecr.io/myrepo/myimage:v1> -AcrPassword <ACR password>
This uploads the container configuration script to the default "publicvstsscript" storage container of the requested Storage Account and then creates 2 Azure Container Instances, based on the custom image provided, with the default settings (Default Agent Pool 1 GB RAM, 1 CPU core, PowerShell modules installed: "Az", "AzureAD", "Pester").
<none>
<none>
- Version: 1.0
- Author: Mate Barabas
- Creation Date: 2018-08-29