java - mvn azure 函数 :deploy creates 'not valid storage account name'

标签 java azure maven azure-functions

我正在按照下面的 Microsoft 教程进行操作,并尝试使用 mvn azure-functions:deploy 命令部署我的 azure 函数。我的函数应用程序名称/artifactid 是 ci-cd-demo: https://azure.microsoft.com/en-us/resources/videos/azure-friday-java-in-azure-functions/

但是,我收到错误:

[ERROR] Failed to execute goal com.microsoft.azure:azure-functions-maven-plugin:1.4.1:deploy (default-cli) on project ci-cd-demo: ci-cd-demod9632762a is not a valid storage account name. Storage account name mu
st be between 3 and 24 characters in length and use numbers and lower-case letters only.

我登录到 Azure 门户并创建了一个存储帐户。我还在命令行中通过 Azure CLI 手动执行此操作。存储帐户是“cicddemo777”。

看起来好像当我运行mvn azure-functions:deploy时,项目找不到存储帐户,因此它创建一个存储帐户并将一堆数字附加到我的函数应用程序名称的末尾。我的 pom.xml 中的 azure-functions-maven-plugin 下有函数应用程序名称、资源组、应用程序服务计划和区域变量。

有没有办法在我的项目中为我的 azure 存储帐户定义属性变量,以便我可以成功运行出现此错误的 azure-functions:deploy 命令?

最佳答案

更新:

感谢enth的分享。此错误来自于 functionAppName 的更改。

(由于FunctionAppName在部署时需要全局唯一,所以默认会生成一串数字。)

原始答案:

mvn azure-functions:deploy主要是第一次使用,因为它产生的文件没有指定。它将生成随机资源,这是设计使然。

看看这个:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-first-java-maven?pivots=java-build-tools-maven#deploy-the-function-to-azure

使用mvn azure-functions:deploy不应该面临问题。你在pom.xml中设置了什么吗?不能有像 - 这样的字符在存储帐户名称中。

这是我的pom.xml,没问题:

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.function</groupId>
<artifactId>ci-cd-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Azure Java Functions</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <azure.functions.maven.plugin.version>1.4.1</azure.functions.maven.plugin.version>
    <azure.functions.java.library.version>1.3.1</azure.functions.java.library.version>
    <functionAppName>ci-cd-demo-20200406102526581</functionAppName>
    <stagingDirectory>${project.build.directory}/azure-functions/${functionAppName}</stagingDirectory>
</properties>

<repositories>
    <repository>
        <id>maven.snapshots</id>
        <name>Maven Central Snapshot Repository</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>maven.snapshots</id>
        <name>Maven Central Snapshot Repository</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.4.2</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>2.23.4</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure.functions</groupId>
            <artifactId>azure-functions-java-library</artifactId>
            <version>${azure.functions.java.library.version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>com.microsoft.azure.functions</groupId>
        <artifactId>azure-functions-java-library</artifactId>
    </dependency>

    <!-- Test -->
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-functions-maven-plugin</artifactId>
                <version>${azure.functions.maven.plugin.version}</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>
        </plugins>
    </pluginManagement>

    <plugins>
        <plugin>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-functions-maven-plugin</artifactId>
            <configuration>
                <!-- function app name -->
                <appName>${functionAppName}</appName>
                <!-- function app resource group -->
                <resourceGroup>java-functions-group</resourceGroup>
                <!-- function app service plan name -->
                <appServicePlanName>java-functions-app-service-plan</appServicePlanName>
                <!-- function app region-->
                <!-- refers https://github.com/microsoft/azure-maven-plugins/tree/develop/azure-functions-maven-plugin#supported-regions for all valid values -->
                <region>westus</region>
                <!-- function pricingTier, default to be consumption if not specified -->
                <!-- refers https://github.com/microsoft/azure-maven-plugins/tree/develop/azure-functions-maven-plugin#supported-pricing-tiers for all valid values -->
                <!-- <pricingTier></pricingTier> -->
                <runtime>
                    <!-- runtime os, could be windows, linux or docker-->
                    <os>windows</os>
                    <!-- for docker function, please set the following parameters -->
                    <!-- <image>[hub-user/]repo-name[:tag]</image> -->
                    <!-- <serverId></serverId> -->
                    <!-- <registryUrl></registryUrl>  -->
                </runtime>
                <appSettings>
                    <property>
                        <name>FUNCTIONS_EXTENSION_VERSION</name>
                        <value>~3</value>
                    </property>
                </appSettings>
            </configuration>
            <executions>
                <execution>
                    <id>package-functions</id>
                    <goals>
                        <goal>package</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <overwrite>true</overwrite>
                        <outputDirectory>${stagingDirectory}</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${project.basedir}</directory>
                                <includes>
                                    <include>host.json</include>
                                    <include>local.settings.json</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${stagingDirectory}/lib</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                        <includeScope>runtime</includeScope>
                        <excludeArtifactIds>azure-functions-java-library</excludeArtifactIds>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <!--Remove obj folder generated by .NET SDK in maven clean-->
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <filesets>
                    <fileset>
                        <directory>obj</directory>
                    </fileset>
                </filesets>
            </configuration>
        </plugin>
    </plugins>
</build>

大多数情况下,您应该选择 func azure functionapp publish <FunctionAppName>部署您的函数应用程序。首先,在Azure上创建一个FunctionApp,然后部署到这个App上。这是文档:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash#publish

关于java - mvn azure 函数 :deploy creates 'not valid storage account name' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61027920/

相关文章:

azure - Azure 可用区的距离有多远?

azure - cloudapp.net 和 azurewebsites.net 之间的区别

java - Maven Arquillian Junit 测试失败

java - 类型不匹配 : cannot convert from DataProvider to Annotation

java - 框架中如何使用反射?

java - 无序 XSD 序列的标准解决方案

java - Intellij maven项目编译 fatal error : invalid flag: --release

java - 为什么我的 JDK11 程序会受到 Windows 7 个性化显示设置的影响?

c# - 在 Azure 上部署的 .Net Core 3.1 Web 应用程序显示错误 HTTP 错误 500.35 - ANCM 同一进程中的多个进程内应用程序

java - 将文件从 Maven 程序集中的 Maven 依赖项中拉出