mvn azure-functions:deploy创建 ‘not valid storage account name’ 错误。

huangapple go评论118阅读模式
英文:

mvn azure-functions:deploy creates 'not valid storage account name'

问题

我正在按照下面的微软教程,并尝试使用 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 must 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 命令而不出现此错误?

英文:

I'm following this microsoft tutorial below and trying to deploy my azure function using the mvn azure-functions:deploy command. My function app name/artifactid is ci-cd-demo:
https://azure.microsoft.com/en-us/resources/videos/azure-friday-java-in-azure-functions/

However, I receive an error:

[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.

I logged into the azure portal and created a Storage account. I also did this manually through the Azure CLI in command line. The storage account is "cicddemo777".

It looks as if when I run mvn azure-functions:deploy , the project cannot find the storage account , so it creates one and appends a bunch of numbers to the end of my function app name. I have the function app name , resource group, appservice plan and region variables in my pom.xml under the azure-functions-maven-plugin.

Is there a way to define the property variable for my azure storage account inside my project so I can successfully run the azure-functions:deploy command with this error?

答案1

得分: 1

更新:

感谢 ennth 的分享。这个错误是由于 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,没有问题:

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <!-- ... 省略其余部分 ... -->
</project>

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

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

英文:

Update:

Thanks for ennth's sharing. This error comes from changing of functionAppName.

(Since FunctionAppName need unique in all of the world when deployed, it will generate a string of numbers by default.)

Original Answer:

mvn azure-functions:deploy is mainly used for the first time, because the files it produces are not specified. It will It generates random resources, which is by design.

Have a look of this:

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

Use mvn azure-functions:deploy should not face problem. Have you set something in pom.xml? There must be no character like - in storage account name.

This is my pom.xml, and it is no problem:

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;>
<modelVersion>4.0.0</modelVersion>

&lt;groupId&gt;com.function&lt;/groupId&gt;
&lt;artifactId&gt;ci-cd-demo&lt;/artifactId&gt;
&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
&lt;packaging&gt;jar&lt;/packaging&gt;
&lt;name&gt;Azure Java Functions&lt;/name&gt;
&lt;properties&gt;
&lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
&lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
&lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
&lt;azure.functions.maven.plugin.version&gt;1.4.1&lt;/azure.functions.maven.plugin.version&gt;
&lt;azure.functions.java.library.version&gt;1.3.1&lt;/azure.functions.java.library.version&gt;
&lt;functionAppName&gt;ci-cd-demo-20200406102526581&lt;/functionAppName&gt;
&lt;stagingDirectory&gt;${project.build.directory}/azure-functions/${functionAppName}&lt;/stagingDirectory&gt;
&lt;/properties&gt;
&lt;repositories&gt;
&lt;repository&gt;
&lt;id&gt;maven.snapshots&lt;/id&gt;
&lt;name&gt;Maven Central Snapshot Repository&lt;/name&gt;
&lt;url&gt;https://oss.sonatype.org/content/repositories/snapshots/&lt;/url&gt;
&lt;releases&gt;
&lt;enabled&gt;false&lt;/enabled&gt;
&lt;/releases&gt;
&lt;snapshots&gt;
&lt;enabled&gt;true&lt;/enabled&gt;
&lt;/snapshots&gt;
&lt;/repository&gt;
&lt;/repositories&gt;
&lt;pluginRepositories&gt;
&lt;pluginRepository&gt;
&lt;id&gt;maven.snapshots&lt;/id&gt;
&lt;name&gt;Maven Central Snapshot Repository&lt;/name&gt;
&lt;url&gt;https://oss.sonatype.org/content/repositories/snapshots/&lt;/url&gt;
&lt;releases&gt;
&lt;enabled&gt;false&lt;/enabled&gt;
&lt;/releases&gt;
&lt;snapshots&gt;
&lt;enabled&gt;true&lt;/enabled&gt;
&lt;/snapshots&gt;
&lt;/pluginRepository&gt;
&lt;/pluginRepositories&gt;
&lt;dependencyManagement&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
&lt;artifactId&gt;junit-jupiter&lt;/artifactId&gt;
&lt;version&gt;5.4.2&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.mockito&lt;/groupId&gt;
&lt;artifactId&gt;mockito-core&lt;/artifactId&gt;
&lt;version&gt;2.23.4&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.microsoft.azure.functions&lt;/groupId&gt;
&lt;artifactId&gt;azure-functions-java-library&lt;/artifactId&gt;
&lt;version&gt;${azure.functions.java.library.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;/dependencyManagement&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.microsoft.azure.functions&lt;/groupId&gt;
&lt;artifactId&gt;azure-functions-java-library&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;!-- Test --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
&lt;artifactId&gt;junit-jupiter&lt;/artifactId&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.mockito&lt;/groupId&gt;
&lt;artifactId&gt;mockito-core&lt;/artifactId&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;pluginManagement&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;com.microsoft.azure&lt;/groupId&gt;
&lt;artifactId&gt;azure-functions-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;${azure.functions.maven.plugin.version}&lt;/version&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
&lt;version&gt;3.1.0&lt;/version&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
&lt;version&gt;3.1.1&lt;/version&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-clean-plugin&lt;/artifactId&gt;
&lt;version&gt;3.1.0&lt;/version&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/pluginManagement&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;com.microsoft.azure&lt;/groupId&gt;
&lt;artifactId&gt;azure-functions-maven-plugin&lt;/artifactId&gt;
&lt;configuration&gt;
&lt;!-- function app name --&gt;
&lt;appName&gt;${functionAppName}&lt;/appName&gt;
&lt;!-- function app resource group --&gt;
&lt;resourceGroup&gt;java-functions-group&lt;/resourceGroup&gt;
&lt;!-- function app service plan name --&gt;
&lt;appServicePlanName&gt;java-functions-app-service-plan&lt;/appServicePlanName&gt;
&lt;!-- function app region--&gt;
&lt;!-- refers https://github.com/microsoft/azure-maven-plugins/tree/develop/azure-functions-maven-plugin#supported-regions for all valid values --&gt;
&lt;region&gt;westus&lt;/region&gt;
&lt;!-- function pricingTier, default to be consumption if not specified --&gt;
&lt;!-- refers https://github.com/microsoft/azure-maven-plugins/tree/develop/azure-functions-maven-plugin#supported-pricing-tiers for all valid values --&gt;
&lt;!-- &lt;pricingTier&gt;&lt;/pricingTier&gt; --&gt;
&lt;runtime&gt;
&lt;!-- runtime os, could be windows, linux or docker--&gt;
&lt;os&gt;windows&lt;/os&gt;
&lt;!-- for docker function, please set the following parameters --&gt;
&lt;!-- &lt;image&gt;[hub-user/]repo-name[:tag]&lt;/image&gt; --&gt;
&lt;!-- &lt;serverId&gt;&lt;/serverId&gt; --&gt;
&lt;!-- &lt;registryUrl&gt;&lt;/registryUrl&gt;  --&gt;
&lt;/runtime&gt;
&lt;appSettings&gt;
&lt;property&gt;
&lt;name&gt;FUNCTIONS_EXTENSION_VERSION&lt;/name&gt;
&lt;value&gt;~3&lt;/value&gt;
&lt;/property&gt;
&lt;/appSettings&gt;
&lt;/configuration&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;package-functions&lt;/id&gt;
&lt;goals&gt;
&lt;goal&gt;package&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;copy-resources&lt;/id&gt;
&lt;phase&gt;package&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;copy-resources&lt;/goal&gt;
&lt;/goals&gt;
&lt;configuration&gt;
&lt;overwrite&gt;true&lt;/overwrite&gt;
&lt;outputDirectory&gt;${stagingDirectory}&lt;/outputDirectory&gt;
&lt;resources&gt;
&lt;resource&gt;
&lt;directory&gt;${project.basedir}&lt;/directory&gt;
&lt;includes&gt;
&lt;include&gt;host.json&lt;/include&gt;
&lt;include&gt;local.settings.json&lt;/include&gt;
&lt;/includes&gt;
&lt;/resource&gt;
&lt;/resources&gt;
&lt;/configuration&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;copy-dependencies&lt;/id&gt;
&lt;phase&gt;prepare-package&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;copy-dependencies&lt;/goal&gt;
&lt;/goals&gt;
&lt;configuration&gt;
&lt;outputDirectory&gt;${stagingDirectory}/lib&lt;/outputDirectory&gt;
&lt;overWriteReleases&gt;false&lt;/overWriteReleases&gt;
&lt;overWriteSnapshots&gt;false&lt;/overWriteSnapshots&gt;
&lt;overWriteIfNewer&gt;true&lt;/overWriteIfNewer&gt;
&lt;includeScope&gt;runtime&lt;/includeScope&gt;
&lt;excludeArtifactIds&gt;azure-functions-java-library&lt;/excludeArtifactIds&gt;
&lt;/configuration&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;!--Remove obj folder generated by .NET SDK in maven clean--&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-clean-plugin&lt;/artifactId&gt;
&lt;version&gt;3.1.0&lt;/version&gt;
&lt;configuration&gt;
&lt;filesets&gt;
&lt;fileset&gt;
&lt;directory&gt;obj&lt;/directory&gt;
&lt;/fileset&gt;
&lt;/filesets&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;

</project>

In most cases, you should choose func azure functionapp publish &lt;FunctionAppName&gt; to deploy your function app. First, create a FunctionApp on Azure, and then deploy to this App. This is the doc:

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

huangapple
  • 本文由 发表于 2020年4月4日 20:14:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/61027920.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定