microsoft / azure-maven-plugins

Maven plugins for Azure
MIT License
276 stars 150 forks source link

Fails deploying azure function using azure cli auth type #2165

Open pankajagrawal16 opened 2 years ago

pankajagrawal16 commented 2 years ago

Plugin name and version

<plugin>
                    <groupId>com.microsoft.azure</groupId>
                    <artifactId>azure-functions-maven-plugin</artifactId>
                    <version>1.21.0</version>
                </plugin>

Plugin configuration in your pom.xml

  <plugin>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-functions-maven-plugin</artifactId>
        <configuration>
                    <resourceGroup>${functionResourceGroup}</resourceGroup>
                    <appName>${functionAppName}</appName>
                    <region>${functionAppRegion}</region>
                    <auth><type>azure_cli</type></auth>
                    <subscriptionId>subscription id</subscriptionId>
                    <appSettings>
                        <!-- Run Azure Function from package file by default -->
                        <property>
                            <name>WEBSITE_RUN_FROM_PACKAGE</name>
                            <value>1</value>
                        </property>
                        <property>
                            <name>FUNCTIONS_EXTENSION_VERSION</name>
                            <value>~4</value>
                        </property>
                        <property>
                            <name>FUNCTIONS_WORKER_RUNTIME</name>
                            <value>java</value>
                        </property>
                    </appSettings>
                </configuration>
                <executions>
                    <execution>
                        <id>package-functions</id>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Expected behavior

should deploy.

Actual behavior

Fails with below error

Caused by: com.microsoft.azure.toolkit.lib.auth.exception.AzureToolkitAuthenticationException: execute Azure Cli command 'az version --output json' failed due to error: Process exited with an error: 2 (Exit value: 2).
    at com.microsoft.azure.toolkit.lib.auth.util.AzureCliUtils.executeAzureCli (AzureCliUtils.java:99)
    at com.microsoft.azure.toolkit.lib.auth.util.AzureCliUtils.ensureMinimumCliVersion (AzureCliUtils.java:31)
    at com.microsoft.azure.toolkit.lib.auth.core.azurecli.AzureCliAccount.lambda$preLoginCheck$2 (AzureCliAccount.java:36)
    at reactor.core.publisher.MonoCallable.subscribe (MonoCallable.java:56)
    at reactor.core.publisher.Mono.subscribe (Mono.java:4150)
    at reactor.core.publisher.Mono.block (Mono.java:1702)

Steps to reproduce the problem

adeabayyup commented 2 years ago

I think it's a typo in your pom.xml. Instead of <auth><type>azure_cli</type></auth> use <authType>azure_cli</authType>

pankajagrawal16 commented 2 years ago

I think it's a typo in your pom.xml. Instead of <auth><type>azure_cli</type></auth> use <authType>azure_cli</authType>

Still fails with same error

wangmingliang-ms commented 1 year ago

I think it's a typo in your pom.xml. Instead of <auth><type>azure_cli</type></auth> use <authType>azure_cli</authType>

Still fails with same error

what did you see when you run az version --output json directly in shell/terminal?

pankajagrawal16 commented 1 year ago

what did you see when you run az version --output json directly in shell/terminal?

{
  "azure-cli": "2.42.0",
  "azure-cli-core": "2.42.0",
  "azure-cli-telemetry": "1.0.8",
  "extensions": {
    "account": "0.2.5",
    "interactive": "0.4.5",
    "storage-preview": "0.8.3"
  }
}
pankajagrawal16 commented 1 year ago

Not sure why but I just tried once again, and this time it seems to work. Super weird. I don't recall doing any kind of changes etc

pankajagrawal16 commented 1 year ago

ok now it fails saying:

Caused by: com.microsoft.azure.toolkit.lib.auth.AzureToolkitAuthenticationException: execute Azure Cli command 'az account list --output json' failed due to error: Process exited with an error: 2 (Exit value: 2).
    at com.microsoft.azure.toolkit.lib.auth.cli.AzureCliUtils.executeAzureCli (AzureCliUtils.java:84)
    at com.microsoft.azure.toolkit.lib.auth.cli.AzureCliUtils.listSubscriptions (AzureCliUtils.java:59)
    at com.microsoft.azure.toolkit.lib.auth.cli.AzureCliAccount.loadSubscriptions (AzureCliAccount.java:55)
    at com.microsoft.azure.toolkit.lib.auth.Account.reloadSubscriptions (Account.java:146)
    at com.microsoft.azure.toolkit.lib.auth.Account.login (Account.java:96)
    at com.microsoft.azure.toolkit.lib.auth.AzureAccount.login (AzureAccount.java:124)
    at com.microsoft.azure.maven.AbstractAzureMojo.loginAzure (AbstractAzureMojo.java:365)
    at com.microsoft.azure.maven.AbstractAzureMojo.loginAzure (AbstractAzureMojo.java:347)
    at com.microsoft.azure.maven.appservice.AbstractAppServiceMojo.initAzureAppServiceClient (AbstractAppServiceMojo.java:150)
    at com.microsoft.azure.maven.function.DeployMojo.d
pankajagrawal16 commented 1 year ago

Bit more investigation, it seems to fail only when attempting to deploy via WSL2 terminal . Seems to work when deploying via powershell terminal.

Why would that be?

wangmingliang-ms commented 1 year ago

thanks for your investigation, we didn't set any restrictions on WSL2, we'll investigate what is wrong. does both az account list --output json and az version --output json works well in your WSL2 terminal?

pankajagrawal16 commented 1 year ago

thanks for your investigation, we didn't set any restrictions on WSL2, we'll investigate what is wrong. does both az account list --output json and az version --output json works well in your WSL2 terminal?

Yes both command works properly when run directly on wsl2 terminal and gives output

jleonelion commented 1 year ago

Up vote. I also have this problem.

wangmingliang-ms commented 1 year ago

@jleonelion @pankajagrawal16 thanks for your report, this bug should be fixed by this PR: https://github.com/microsoft/azure-maven-plugins/pull/2183. the fix would be included in the next release v1.23.0

pankajagrawal16 commented 1 year ago

Nice @wangmingliang-ms ! 🎉