Deployment using az.exe
  • 25 Jan 2023
  • 1 Minute to read
  • Dark
    Light
  • PDF

Deployment using az.exe

  • Dark
    Light
  • PDF

When using BuildMaster to deploy applications, you may first need to create the target you want to deploy to. This is a typical solution if you want to access cloud services such as Microsoft Azure.

Before We Begin

To deploy Azure resources within BuildMaster, you will first need to
Install Azure CLI on the machine where BuildMaster is installed. Once installed, you can execute Azure CLI commands against your Azure subscription after you execute the login command. We recommend logging in to Azure using a service principal instead of a user name/password. You will need to create a service principal with Azure CLI before starting.

Implementation

As mentioned before, in order to execute Azure command line functions you will need to login to Azure to associate the action you are performing with an Azure subscription. We recommend that you combine the Azure login and the Azure command into one OtterScript module such as this one.

Azure-Execute Module:

module Azure-Execute<$args>
{

    set $ExeFileName = "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd";

    InedoCore::Exec
    (
        FileName: $ExeFileName,
        Arguments: login --service-principal -u <url> -p <password> --tenant <tenant>
    );

    InedoCore::Exec
    (
        FileName: ExeFileName,
        Arguments: $args
    );
}

Once created as a global module, Azure-Execute can now be used easily from any OtterScript plan in BuildMaster to start creating resources such as databases, virtual machines, and more.

Create a Resource Group Named After Your BuildMaster Application

call Azure-Execute
(
    args: group create --name $ApplicationName-rg --location centralus
);

This runs these two commands to create a resource group in Azure.

az login --service-principal -u <url> -p <password> --tenant <tenant>
az group create --name $ApplicationName-rg --location centralus

More Commands

Create a SQL Server on Azure in the Resource Group You Created

call Azure-Execute
(
    args: sql server create --admin-password mysecret --admin-user $ApplicationName-admin  --name $ApplicationName-server --resource-group $ApplicationName-rg --location centralus 
);

Create a Standard S0 Database Named After Your BuildMaster Pipeline

InedoCore::Exec
(
    FileName: "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd",
    Arguments: sql db create -g $ApplicationName-rg -s $ApplicationName-server -n $PipelineName-db --service-objective S0
);

Was this article helpful?

What's Next