Java 如何动态注入<;认证>;进入azure webapp maven插件?
默认情况下,Azure deploy maven命令应该在本地开发人员机器上使用自动登录身份验证(带有登录代码的URL)。但是,CI服务器将为登录注入额外的服务主体参数 给定“pom.xml”配置Java 如何动态注入<;认证>;进入azure webapp maven插件?,java,azure,maven,web-applications,Java,Azure,Maven,Web Applications,默认情况下,Azure deploy maven命令应该在本地开发人员机器上使用自动登录身份验证(带有登录代码的URL)。但是,CI服务器将为登录注入额外的服务主体参数 给定“pom.xml”配置 <plugin> <groupId>com.microsoft.azure</groupId> <artifactId>azure-webapp-maven-plugin</artifactId>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<version>${azure-webapp-maven-plugin.version}</version>
<configuration>
<schemaVersion>${azure-webapp-maven-plugin.schema.version}</schemaVersion>
<allowTelemetry>false</allowTelemetry>
<subscriptionId>${azure.subscription.id}</subscriptionId>
<resourceGroup>${azure.resourcegroup}</resourceGroup>
<appName>${azure.appservice.name}</appName>
<appServicePlanName>${azure.appservice.plan.name}</appServicePlanName>
<pricingTier>${azure.appservice.plan.pricingtier}</pricingTier>
<region>${azure.region}</region>
<runtime>
<os>${azure.appservice.plan.os}</os>
<javaVersion>${azure.java.version}</javaVersion>
<webContainer>${azure.java.version}</webContainer>
</runtime>
<appSettings>
<property>
<name>JAVA_OPTS</name>
<value>-Dserver.port=80</value>
</property>
</appSettings>
<deployment>
<resources>
<resource>
<directory>${project.basedir}/target</directory>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
</deployment>
</configuration>
</plugin>
我试图在命令行上将
定义为插件参数,但无法确定动态设置它的路径(例如-Dwebapp.authentication.serverId=azure auth
仍然会导致URL提示输入登录代码,而不是使用服务主体凭据).我找到了一种替代配置的方法,但更喜欢通过maven命令参数进行动态配置
“pom.xml”
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<properties>
<azure.tenant.id>
<!--
Set the Azure subscription identifier via command line:
./mvnw -s ./ci-settings.xml ... "-Dazure.tenant.id=enter-value-here"
-->
</azure.tenant.id>
<azure.client.id>
<!--
Set the Azure service principal identifier via command line:
./mvnw -s ./ci-settings.xml ... "-Dazure.client.id=enter-value-here"
-->
</azure.client.id>
<azure.client.key>
<!--
Set the Azure service principal password via command line:
./mvnw -s ./ci-settings.xml ... "-Dazure.client.key=enter-value-here"
-->
</azure.client.key>
</properties>
</profile>
</profiles>
<servers>
<server>
<id>azure-auth</id>
<configuration>
<tenant>${azure.tenant.id}</tenant>
<client>${azure.client.id}</client>
<key>${azure.client.key}</key>
<environment>AZURE</environment>
</configuration>
</server>
</servers>
</settings>
./mvnw -B -s ./settings.xml \
clean package azure-webapp:deploy \
"-Dazure.tenant.id=$(tenant-id)" \
"-Dazure.client.id=$(client-id)" \
"-Dazure.client.key=$(client-key)" \
"-Dazure.subscription.id=$(subscription-id)" \
"-Dazure.resourcegroup=$(resource-group)" \
"-Dazure.region=$(region)" \
"-Dazure.appservice.name=$(appservice-name)" \
"-Dazure.appservice.plan.name=$(appservice-plan-name)" \
"-Dazure.appservice.plan.os=$(appservice-plan-os)" \
"-Dazure.appservice.plan.pricingtier=$(appservice-plan-tier)"
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
<relativePath />
<!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>spring-boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot</name>
<description>Demo project for Spring Boot</description>
<properties>
<azure-maven-plugin.version>0.2.0</azure-maven-plugin.version>
<azure-webapp-maven-plugin.version>1.8.0</azure-webapp-maven-plugin.version>
<azure-webapp-maven-plugin.schema.version>V2</azure-webapp-maven-plugin.schema.version>
<java.version>11</java.version>
<azure.java.version>java11</azure.java.version>
<azure.client.id>
<!--
For CI, Set the Azure service principal identifier via command line:
./mvnw ... "-Dazure.client.id=enter-value-here"
-->
</azure.client.id>
<azure.client.key>
<!--
For CI, Set the Azure service principal password via command line:
./mvnw ... "-Dazure.client.key=enter-value-here"
-->
</azure.client.key>
<azure.tenant.id>
<!--
For CI, Set the Azure tenant identifier via command line:
./mvnw ... "-Dazure.tenant.id=enter-value-here"
-->
</azure.tenant.id>
<azure.subscription.id>
<!--
Set the Azure subscription identifier via command line:
./mvnw ... "-Dazure.subscription.id=enter-value-here"
-->
</azure.subscription.id>
<azure.resourcegroup>
<!--
Set the Azure resource group via command line:
./mvnw ... "-Dazure.resourcegroup=enter-value-here"
-->
</azure.resourcegroup>
<azure.region>
eastus
<!--
Override the Azure region via command line:
./mvnw ... "-Dazure.region=enter-value-here"
-->
</azure.region>
<azure.appservice.name>
<!--
Set the Azure App Service name via command line:
./mvnw ... "-Dazure.appservice.name=enter-value-here"
-->
</azure.appservice.name>
<azure.appservice.plan.name>
<!--
Set the Azure App Service plan name via command line:
./mvnw ... "-Dazure.appservice.plan.name=enter-value-here"
-->
</azure.appservice.plan.name>
<azure.appservice.plan.os>
linux
<!--
Override the Azure App Service plan name via command line:
./mvnw ... "-Dazure.appservice.plan.os=enter-value-here"
-->
</azure.appservice.plan.os>
<azure.appservice.plan.pricingtier>
B1
<!--
Override the Azure App Service plan name via command line:
./mvnw ... "-Dazure.appservice.plan.pricingtier=enter-value-here"
-->
</azure.appservice.plan.pricingtier>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- tag::actuator[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- end::actuator[] -->
<!-- tag::tests[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- end::tests[] -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<version>${azure-webapp-maven-plugin.version}</version>
<configuration>
<schemaVersion>${azure-webapp-maven-plugin.schema.version}</schemaVersion>
<allowTelemetry>false</allowTelemetry>
<subscriptionId>${azure.subscription.id}</subscriptionId>
<resourceGroup>${azure.resourcegroup}</resourceGroup>
<appName>${azure.appservice.name}</appName>
<appServicePlanName>${azure.appservice.plan.name}</appServicePlanName>
<pricingTier>${azure.appservice.plan.pricingtier}</pricingTier>
<region>${azure.region}</region>
<runtime>
<os>${azure.appservice.plan.os}</os>
<javaVersion>${azure.java.version}</javaVersion>
<webContainer>${azure.java.version}</webContainer>
</runtime>
<appSettings>
<property>
<name>JAVA_OPTS</name>
<value>-Dserver.port=80</value>
</property>
</appSettings>
<deployment>
<resources>
<resource>
<directory>${project.basedir}/target</directory>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
</deployment>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>deploy-ci</id>
<activation>
<property>
<name>azure.client.id</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<version>${azure-webapp-maven-plugin.version}</version>
<configuration>
<auth>
<tenant>${azure.tenant.id}</tenant>
<client>${azure.client.id}</client>
<key>${azure.client.key}</key>
<environment>AZURE</environment>
</auth>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
deploy:
ifdef CI
@./mvnw azure-webapp:deploy \
"-Dazure.tenant.id=$(tenant-id)" \
"-Dazure.client.id=$(client-id)" \
"-Dazure.client.key=$(client-key)" \
"-Dazure.subscription.id=$(subscription-id)" \
"-Dazure.resourcegroup=$(resource-group)" \
"-Dazure.region=$(region)" \
"-Dazure.appservice.name=$(appservice-name)" \
"-Dazure.appservice.plan.name=$(appservice-plan-name)" \
"-Dazure.appservice.plan.os=$(appservice-plan-os)" \
"-Dazure.appservice.plan.pricingtier=$(appservice-plan-tier)"
else
@./mvnw azure-webapp:deploy \
"-Dazure.subscription.id=$(subscription-id)" \
"-Dazure.resourcegroup=$(resource-group)" \
"-Dazure.region=$(region)" \
"-Dazure.appservice.name=$(appservice-name)" \
"-Dazure.appservice.plan.name=$(appservice-plan-name)" \
"-Dazure.appservice.plan.os=$(appservice-plan-os)" \
"-Dazure.appservice.plan.pricingtier=$(appservice-plan-tier)"
endif