我正在使用 Bicep 模板和 Quarkus 框架部署 Azure Function App,但部署失败并出现以下错误: 任务“:quarkus:deploy”执行失败。
io.quarkus.builder.BuildException:构建失败:由于错误而构建失败 [错误]:构建步骤 io.quarkus.azure.functions.deployment.AzureFunctionsDeployCommand#deploy 引发异常:java.lang.NullPointerException 在 com.microsoft.azure.toolkit.lib.appservice.task.DeployFunctionAppTask.doExecute(DeployFunctionAppTask.java:86) 在 io.quarkus.azure.functions.deployment.AzureFunctionsDeployCommand.deployArtifact(AzureFunctionsDeployCommand.java:355) 在 io.quarkus.azure.functions.deployment.AzureFunctionsDeployCommand.deploy(AzureFunctionsDeployCommand.java:120) ...
堆栈跟踪表明 DeployFunctionAppTask.doExecute 方法中使用了 null 值。我怀疑这可能与缺少配置或环境变量有关。
采取的故障排除步骤:
已验证存储帐户名称和密钥是否已正确检索。
确保在管道和函数应用程序中设置 AzureWebJobsStorage 和 FUNCTIONS_WORKER_RUNTIME 环境变量。
确认 Bicep 模板提供了所有必需的资源,并包含 dependentOn 以避免竞争条件。
使用 Gradle 的 --debug 和 --stacktrace 选项运行部署,但找不到 NullPointerException 的明确解释。
什么可能导致 DeployFunctionAppTask.doExecute 方法中出现 NullPointerException?
使用 Quarkus 部署 Azure Function App 时是否可能缺少其他配置或环境变量?
如何进一步调试此问题以确定根本原因?
@FunctionName("GetReportsByAirportCode")
fun getReportsByAirportCode(
@HttpTrigger(
name = "req",
methods = [HttpMethod.GET],
authLevel = AuthorizationLevel.ANONYMOUS,
route = "v1/reports/by-airport-code"
) request: HttpRequestMessage<Any>,
context: ExecutionContext
): HttpResponseMessage {
return try {
val bearerToken = request.headers["authorization"]
?: return unauthorizedResponse(request, "Missing Authorization Header")
val profile = authService.validateAccessTokenAndGetProfileRequest(bearerToken)
val query = request.queryParameters["query"]
val page = request.queryParameters["page"]?.toIntOrNull() ?: -1
val size = request.queryParameters["size"]?.toIntOrNull() ?: -1
if (page < 0 || size < 0 || size > maxPageSize) {
return badRequestResponse(request, "Invalid parameters")
}
val assignedAirports = authService.getAssignedAirports(bearerToken)
if (assignedAirports.isEmpty()) {
return forbiddenResponse(request, "User is not assigned to any airports")
}
val reports = reportRepository.findByAirportCodes(page, size, assignedAirports, query)
request.createResponseBuilder(HttpStatus.OK)
.header("Content-Type", "application/json")
.body(reports)
.build()
} catch (e: Exception) {
context.logger.severe("Error fetching reports: ${e.message}")
e.toResponse(request)
}
}
Quarkus extension
:plugins {
id 'java'
id 'io.quarkus'
}
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
implementation 'io.quarkus:quarkus-azure-functions'
implementation 'io.quarkus:quarkus-arc'
implementation 'com.microsoft.azure.functions:azure-functions-java-library'
testImplementation 'io.quarkus:quarkus-junit5'
testImplementation 'io.rest-assured:rest-assured'
testImplementation 'org.mockito:mockito-core'
}
group 'org.acme'
version '1.0.0-SNAPSHOT'
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
test {
systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
}
compileJava {
options.encoding = 'UTF-8'
options.compilerArgs << '-parameters'
}
compileTestJava {
options.encoding = 'UTF-8'
}
application.properties
中配置所需的应用程序设置。gradle clean build
以清除冲突。gradle azureFunctionsDeploy
进行部署来测试部署。Command: gradle azure-functions:deploy (or) gradle azureFunctionsDeploy
//Removed few logs
[INFO] Deployment succeed
[INFO] Syncing triggers and fetching function information
[INFO] Querying triggers...
[INFO] HTTP Trigger Urls:
HttpExample : https://<function_name>.azurewebsites.net/api/HttpExample
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------