API Version Error

When running an Octopus Deployment using a powershell script I am getting the error:

Get-AzureRmResource : MissingApiVersionParameter : The api-version query

When I run the script on the Octopus server manually I do not get the error. I change the package to include the api-version on the call, uploaded it to the octopus server and I still got the error.

Hi Brian,

Thanks for getting in touch! I’m sorry you’re hitting this error. I suspect it could come down to having multiple versions of the Azure SDKs on the server, as the command is successful when run manually on the server compared to failing when run from your package. Octopus bundles a version of Azure modules, which it uses by default. You can override this default version and use your version of the modules installed on the server. That can be done simply by adding the following variable to your project:

Octopus.Action.Azure.UseBundledAzurePowerShellModules with a value of False

If that’s the case, then you won’t need to use the ApiVersion parameter, as it’ll use the same version as when you run it manually.

In case I’m off the mark - what kind of resource are you trying to retrieve? It’s possible it works only for one resource-type, but not another.

Let me know how you go or if you have any other questions or concerns.

Kind regards,

Kenny

Kenny,
I already had the variable set to false when I got the error. I am trying to get the Azure Key vault id. I am using the command Get-AzureRmResource -ResourceId and I am using the resource id for the for the key vault.

I have tried adding the api-version to the command. I have also checked to make sure I only have one version of AzureRm, Azure and AzureRm.Keyvault installed.

Hi Brian,

Can you confirm you’re using an Azure PowerShell Script step as opposed to a standard PowerShell Script step? The Azure specific step users your selected Azure account’s info during a deployment, and automatically loads the modules. The standard PS script step won’t automatically load modules (you would need to manually import them in the script), so setting that variable won’t do anything if that’s the case.

If you are already using the Azure step, could you attach a full verbose deployment log? The following link outlines the process of enabling the debugging variables, creating and deploying a new release, then exporting the resulting log.

https://octopus.com/docs/how-to/how-to-turn-on-variable-logging-and-export-the-task-log

That will give us more insight to continue troubleshooting why you’re experiencing this issue.

I look forward to hearing back!

Kenny

Kenny,
I found the problem. I have 2 processes in a project. The first process loads variables to be used by the second using Set-OctopusVariable. When I try to access them in the second process using the variable #{Octopus.Action[Get Deployment Resources].Output.deploymentVaultResourceId} I would get the error. It was because the original process I was using to load the variables was named “01 Get Deployment Resources” and not “Get Deployment Resources”. When I renamed it to the proper process name it worked.

Hi Brian,

Thanks for letting me know how you resolved this. It’s great to hear you’re up and running :slight_smile:

Don’t hesitate to reach out if you have any further questions!

Kenny