azure-maven-plugins
azure-maven-plugins copied to clipboard
Support AZURE_CONFIG_DIR
Plugin name and version
azure-webapp-maven-plugin 1.6.0
Plugin configuration in your pom.xml
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<allowTelemetry>false</allowTelemetry>
<appName>${deployment.appName}</appName>
<resourceGroup>${deployment.resourceGroup}</resourceGroup>
<pricingTier>F1</pricingTier>
<javaVersion>1.8</javaVersion>
<stopAppDuringDeployment>true</stopAppDuringDeployment>
</configuration>
</plugin>
Expected behavior
The Maven plugin uses the right configuration directory, set via AZURE_CONFIG_DIR
as described in the documentation for Azure CLI.
Actual behavior
The plugin always uses the configuration in $HOME/.azure
if present.
If that is missing, an error is thrown:
[INFO] Authenticate with Azure CLI 2.0
Cannot read files .../.azure/azureProfile.json and .../.azure/accessTokens.json. Are you logged in Azure CLI?
Steps to reproduce the problem
- Ensure
$HOME/.azure
is missing (e.g., move it away, or delete it) - Set
AZURE_CONFIG_DIR
to something else than$HOME
, e.g.,export AZURE_CONFIG_DIR="$(mktemp)"
(under Linux in a Bash) - Run
mvn azure-webapp:deploy
As far as I can tell, the Maven plugin uses System.getProperty("user.home")
to find the Azure CLI configuration files in two places:
- src/main/java/com/microsoft/azure/maven/AbstractAzureMojo.java
- src/main/java/com/microsoft/azure/maven/auth/AzureAuthHelper.java
It might be feasible to replace that with a helper method that looks up System.getenv(AZURE_CONFIG_DIR)
first with a fallback to System.getProperty("user.home")
.
Alternatively, it might be a good idea to expose the path as Maven property.
FWIW, I created a quick hack and opened PR #674 for this issue. I hope that is okay.
@alexandrospanagiotidis Thanks for your report and your contribution! Maven Plugin use $HOME/.azure
as the config folder to save some configurations, and we use AzureCliCredentials.create()
to get the Authenticated object from Azure CLI, which uses $HOME/.azure
as the path for cli config folder. I've opened an issue here.
Codes which refers $HOME/.azure
in AzureAuthHelper
is the workaround to solve AzureCliCredentials
can't get the correct subscription in azure cloud shell or cli authed with service principal, we will fix them once the issue is fixed.
Hi @Flanker32, thank you for your reply. Should I delete my PR, since this is something that needs to be fixed via the other issue?
@alexandrospanagiotidis Yes, thanks for your support, I'll track this issue and fixed it once the related one is done.
Hi @alexandrospanagiotidis, we have already solve this issue by adopting azure-identity, could you please take a try again.
Dear @andxu,
Thank you for your reply! I am no longer able to test your changes, as I am no longer involved in that particular project.
As a side-note: we moved away from deploying via azure-maven-plugin
(in favor of az-cli
) as we needed to set a higher timeout for deployments to Azure China, which was not possible with the plugin at that time.
Thank you for your efforts!
All the best Alex