Azure module errors when running Azure script

Hi,
We are currently facing a failed deployment on our Octopus cloud instance in a Run an Azure script step. The error we are getting is "ObjectNotFound: The term ‘Get-AzureRole’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. ". We are experiencing similar errors (ObjectNotFound: The term ‘az’ is not recognized as the name of a cmdlet) in few of our projects with different Azure module errors. We came across Configure Az Module when running Azure Script and we didn’t want to add more steps in scripts to install the missing module so tried using the Execution containers but still ended up with this error. I just wanted to make sure if Static Worker is the only option left for us to try or do you have any suggestions for us?

Hi @subadhra.raja,

Thank you for reaching out, and I’d be happy to help with the issue you’re having in using the Run an Azure Script step.

From the error you’ve provided, it looks like your worker does not have the tools installed to properly interact with Azure. I see you mentioned trying to leverage Execution Containers for this, which should have given you access to the Azure tooling - can you let me know what issues you ran into?

I set up a sample step on my side using the Ubuntu Linux worker tools image and was able to run an Azure command as expected:

Can you compare your setup against mine and let me know if you notice any differences/issues?

Best regards,

Britton

Hi @britton.riggs,

Thanks for the quick response. Actually I was using the Default worker pool and the windows image octopusdeploy/worker-tools:3.3.2-windows.ltsc2019 to run the script.

But this time I tried with the Hosted Ubuntu and octopusdeploy/worker-tools:3.3.2-ubuntu.18.04 like you mentioned but still getting the following Azure error
Loading the management certificate
16:35:55 Info | Attempt 4 of 5 failed: The term ‘Get-AzureEnvironment’ is not recognized as the name of a cmdlet, function, script file, or operable program.
16:35:55 Info | Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
16:35:59 Info | Waiting for 5 seconds before retrying…
16:35:59 Info | Retrying…
16:35:59 Verbose | Loading the management certificate
16:35:59 Error | ObjectNotFound: The term ‘Get-AzureEnvironment’ is not recognized as the name of a cmdlet, function, script file, or operable program.
16:35:59 Error | Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
16:35:59 Error | At /home/Octopus/Work/20220628163526-4926-18/Octopus.AzureContext.ps1:222 char:33
16:35:59 Error | + $AzureEnvironment = Get-AzureEnvironment | Where-Object { …
16:35:59 Error | + ~~~~~~~~~~~~~~~~~~~~
16:35:59 Error | at , /home/Octopus/Work/20220628163526-4926-18/Octopus.AzureContext.ps1: line 222
16:35:59 Error | at Execute-WithRetry, /home/Octopus/Work/20220628163526-4926-18/Octopus.AzureContext.ps1: line 50
16:35:59 Error | at , /home/Octopus/Work/20220628163526-4926-18/Octopus.AzureContext.ps1: line 136
16:35:59 Error | at , /home/Octopus/Work/20220628163526-4926-18/Bootstrap.Octopus.AzureContext.ps1: line 2141
16:35:59 Error | at , : line 1
16:35:59 Error | at , : line 1
16:35:59 Error | Running rollback behaviours…

Please advise.

Hi @subadhra.raja,

Is the Get-AzureEnvironment command part of the script that you’re attempting to run?
If so, that command isn’t included in the Azure CLI that is installed within the worker tools image.

Your options here would be to check whether there is a new version of that command that is included within the Azure CLI and then update your script to use that instead or create your own docker image or static worker that includes the required Azure modules for your script.

If not, is your Azure account configured to use a Management Certificate? If so, you could try changing this to use a Service Principal instead as Management Certificates have been deprecated by Microsoft.

Regards,
Paul

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.