Azure Cli 2.0 and existing Service Principal

We have an Azure subscription account setup in octopus which we use to deploy Azure websites sucsessfully.

Now would like to use some of the new functionality in the Azure 2.0 CLI.
I’ve installed the CLI on the server and now need to authenticate.

Is there a way I can use the Azure subscription account service principal to connect via the new ‘az login’, perhaps with az login --service-principal ?

Ocotopus version = 2018.5.1

Cheers,
Dave

Hi Dave,

Thanks for getting in touch.

We don’t support the Azure CLI out of the box, but all the information you need to get it to work is available in the Azure PowerShell step.

Using the PowerShell code that Calamari uses to establish an Azure Security Context, you can get the Azure CLI to login the same way.

Put this line at the top of your script to get the Azure CLI to login:

az login --service-principal -u $OctopusAzureADClientId -p $OctopusAzureADPassword --tenant $OctopusAzureADTenantId

To get this to work for me I also had to append the Azure CLI install location to my path:

$env:Path += ";C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin"

Hopefully this helps you out.

Regards
Ben

1 Like

Awesome, thanks @benpearce and cheers for the link to the Calmari code base. Didnt think to look for that / realise it was open source.