You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Pipeline构建Spring Boot Event Hub函数报Core Tools缺失错误

问题描述

参考Azure Functions官方示例开发基于Spring Boot、由Azure Event Hub消息触发的Java函数,将示例中的HTTP触发逻辑修改为Event Hub触发后,本地通过Maven插件构建、部署到Azure环境均运行正常,但使用Azure Pipeline执行代码构建时出现报错,核心报错信息如下:

[INFO] Step 8 of 8: Installing function extensions if needed
[WARNING] Failed to get Azure Functions Core Tools version locally
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  03:17 min
[INFO] Finished at: 2022-06-25T13:39:48Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.microsoft.***:***-functions-maven-plugin:1.14.2:package (package-functions) on project cutcloud-token-service: Local Azure Functions Core Tools does not exist or is too old to support function extension installation, skip package phase. To install or update it, see: https://aka.ms/azfunc-install -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
The process '/usr/bin/mvn' failed with exit code 1

使用的Azure Pipeline配置如下:

trigger:
  branches:
    include:
      - master

stages:
  - stage: Build
    jobs:
      - job: Build
        steps:
          - task: MavenAuthenticate@0
            inputs:
              mavenServiceConnections: 'nexus'

          - task: Maven@3
            inputs:
              mavenPomFile: 'pom.xml'
              publishJUnitResults: true
              testResultsFiles: '**/surefire-reports/TEST-*.xml'
              javaHomeOption: 'JDKVersion'
              jdkVersionOption: 11
              mavenVersionOption: 'Default'
              mavenAuthenticateFeed: false
              effectivePomSkip: false
              sonarQubeRunAnalysis: false
              goals: clean package
已排查情况

项目pom.xml基于官方示例修改,新增了业务逻辑所需的第三方依赖,已尝试调整azure-functions-maven-plugin、Azure Functions Java库、函数运行时、扩展Bundle等组件的多个版本,均未解决问题。测试复现两个明确现象:

  • 不对代码和pom.xml做任何其他修改,仅注释掉触发方法上的@EventHubTrigger注解,Pipeline构建即可正常通过,相关代码如下:
@FunctionName("createAndSendToken")
  public void run(
//      @EventHubTrigger(name = "apiTokenRequests",
//          eventHubName = "api-key-requests",
//          connection = "EventhubConnectionString",
//          consumerGroup = "digiapp",
//          cardinality = Cardinality.ONE)
      String payload,
      final ExecutionContext context
  ) {
    context.getLogger().info("EventHub trigger function execution started");
    context.getLogger().info("payload:" + payload);
    KeyResponse keyResponse = handleRequest(new KeyRequest(payload), context);
    context.getLogger().info("EventHub trigger function execution finished with status " + keyResponse.getStatus());
  }
  • 早期开发的未使用Spring Boot的纯Java版本同逻辑Event Hub触发函数,在Azure Pipeline中可正常构建,无该报错。
    另外已尝试切换ubuntu-latest、ubuntu-22.04等不同构建代理镜像,问题仍存在。
根因说明

azure-functions-maven-plugin在打包阶段如果检测到项目存在HTTP以外的触发绑定(比如本次的Event Hub触发),会自动执行函数扩展安装步骤,该步骤强依赖构建环境中安装Azure Functions Core Tools。Azure Pipeline默认托管的Ubuntu构建代理没有预装该工具,就会抛出本次报错。
两个现象的原因也对应这个逻辑:

  1. 注释掉@EventHubTrigger注解后,插件检测不到非HTTP绑定,不会触发扩展安装步骤,自然不会校验Core Tools存在性,构建正常通过
  2. 非Spring的纯Java老项目构建正常,是因为使用的低版本maven插件默认没有开启打包阶段自动安装扩展的逻辑,不会触发Core Tools校验
解决方案

二选一即可,优先选方案2,配置成本最低。

方案1:构建环境预装Azure Functions Core Tools

在Pipeline的Maven构建任务前新增Bash脚本步骤,在Ubuntu代理上安装对应大版本的Azure Functions Core Tools,再执行Maven构建即可通过校验。

方案2:跳过插件的自动扩展安装步骤

只要项目的host.json中已经正确配置了扩展Bundle,函数运行时启动时会自动拉取所有需要的绑定扩展,完全不需要在构建阶段执行扩展安装操作。直接在pom.xml的azure-functions-maven-plugin配置块中增加如下参数,跳过构建阶段的扩展安装逻辑即可:

<plugin>
  <groupId>com.microsoft.azure</groupId>
  <artifactId>azure-functions-maven-plugin</artifactId>
  <configuration>
    <!-- 保留原有其他配置不变,新增下面这行 -->
    <installExtensions>false</installExtensions>
  </configuration>
</plugin>

该方案不需要修改Pipeline配置,也不需要在构建代理预装额外依赖,配置完成后重新执行Pipeline即可正常构建。

内容的提问来源于stack exchange,提问作者gofrm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.29 06:30:46