Categories
Azure

Azure CLI, api-version is invalid

I supported with an issue involving the Azure CLI being called in an Azure DevOps Pipeline.

- task: AzureCLI@2
  displayName: Create Deployment Slot
  inputs:
    azureSubscription: "${{ variables.Azure_Subscription }}"
    scriptType: "bash"
    scriptLocation: "inlineScript"
    inlineScript: |
      az webapp deployment slot create 
        --name "${{ variables.Azure_WebAppName }}" 
        --resource-group "${{ variables.Azure_ResourceGroup }}" 
        --slot "${{ variables.Azure_DeploymentSlotName }}" 
        --configuration-source "${{ variables.Azure_WebAppName }}" 

It’s returning the error “InvalidApiVersionParameter” along with “The api-version ‘2023-01-01’ is invalid.”

ERROR: (InvalidApiVersionParameter) The api-version '2023-01-01' is invalid. The supported versions are '2023-07-01,2023-07-01-preview,2023-03-01-preview,2022-12-01,2022-11-01-preview,2022-09-01,2022-06-01,2022-05-01,2022-03-01-preview,2022-01-01,2021-04-01,2021-01-01,2020-10-01,2020-09-01,2020-08-01,2020-07-01,2020-06-01,2020-05-01,2020-01-01,2019-11-01,2019-10-01,2019-09-01,2019-08-01,2019-07-01,2019-06-01,2019-05-10,2019-05-01,2019-03-01,2018-11-01,2018-09-01,2018-08-01,2018-07-01,2018-06-01,2018-05-01,2018-02-01,2018-01-01,2017-12-01,2017-08-01,2017-06-01,2017-05-10,2017-05-01,2017-03-01,2016-09-01,2016-07-01,2016-06-01,2016-02-01,2015-11-01,2015-01-01,2014-04-01-preview,2014-04-01,2014-01-01,2013-03-01,2014-02-26,2014-04'.
Code: InvalidApiVersionParameter

The error could mean a variety of things. In my case, it simply meant that the variables did not contain any values, which resulted in the Azure CLI being called with empty values. Instead of displaying this, it returned an error regarding “(InvalidApiVersionParameter) The api-version ‘2023-01-01’ is invalid.”.

az webapp deployment slot create --name "" --resource-group "" --slot "staging" --configuration-source ""

I fixed the variable naming and values, and the pipeline started working as expected.