【问题标题】:Unhandled: Not found mavenPOMFile - Azure DevOps pipeline for Java Function App未处理:未找到 mavenPOMFile - Java Function App 的 Azure DevOps 管道
【发布时间】:2020-08-14 13:40:04
【问题描述】:

我想创建部署 Java Azure Function 的管道,但失败了。请给我建议。 我以教程为基础,但我使用的是 Azure DevOps 的 Git Repo 而不是 GitHub。 https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/java-function?view=azure-devops

POM 文件位于 /pipelines-java-function-master/pom.xml 的 zip 文件中

我的错误是:

 Starting: Maven
 ==============================================================================
 Task         : Maven
 Description  : Build, test, and deploy with Apache Maven
 Version      : 3.168.0
 Author       : Microsoft Corporation
 Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/maven
 ==============================================================================
 ##[error] Unhandled: Not found mavenPOMFile: /home/vsts/work/1/s/pom.xml
 Finishing: Maven

我的 YAML 是:

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

# at the top of your YAML file 
# set some variables that you'll need when you deploy
variables:
  # the name of the service connection that you created above
  serviceConnectionToAzure: name-of-your-service-connection
  # the name of your web app here is the same one you used above
  # when you created the web app using the Azure CLI
  appName: JavaFuncApp

# ...

# Maven
# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/java

steps:
- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
    mavenOptions: '-Xmx3072m'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.8'
    jdkArchitectureOption: 'x64'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    goals: 'package'


    # ...
# add these as the last steps
# to deploy to your app service
- task: CopyFiles@2
  displayName: Copy Files
  inputs:
    SourceFolder: $(system.defaultworkingdirectory)/target/azure-functions/
    Contents: '**'
    TargetFolder: $(build.artifactstagingdirectory)   

- task: PublishBuildArtifacts@1
  displayName: Publish Artifact
  inputs:
    PathtoPublish: $(build.artifactstagingdirectory)    


- task: AzureWebApp@1
  inputs:
    azureSubscription: 'connection-to-MyTestRG-rg'
    appType: 'webApp'
    appName: '$(appName)'
    package: '$(System.DefaultWorkingDirectory)/pipelines-java-function-master.zip'
    deploymentMethod: 'auto'

【问题讨论】:

  • 请问这个周末后的状态如何?

标签: java azure-devops azure-functions


【解决方案1】:

POM 文件位于 zip 文件中 /pipelines-java-function-master/pom.xml

这就是您遇到错误消息Not found mavenPOMFile 的原因。

对于大多数任务,一旦我们的系统检测到源中存在一个存档文件,就会调用内置脚本来提取存档文件。

但是,对于Maven 任务,我们还没有提供这样的内置脚本。这时候任务会按照正常的工作逻辑去尝试通过$(System.DefaultWokingDirectory)找到pom.xml

如您所说,pom.xml 位于 zip 文件中。由于 zip 尚未解压缩,因此 zip 将被视为文件而不是文件夹。换句话说,pom.xml 似乎从未出现在 Maven 任务中。然后任务告诉你,对不起,我们现在找不到pom.xml


根据您的情况,您应该运行Extract file 任务以使压缩文件在Maven 任务运行之前解压缩。

在示例 YAML 脚本下方,您可以参考:

steps:
- task: ExtractFiles@1
  inputs:
    archiveFilePatterns: '*.zip'
    destinationFolder: '$(Build.SourcesDirectory)'
    cleanDestinationFolder: false

- task: Maven@3
  inputs:
    mavenPomFile: '$(System.DefaultWorkingDirectory)/{zip file name}/pipelines-java-function-master/pom.xml'
    mavenOptions: '-Xmx3072m'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.8'
    jdkArchitectureOption: 'x64'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    goals: 'package'

只需注意mavenPomFile 的值。由于Extract file任务会在工作目录下创建一个与zip文件同名的文件夹,请用硬编码配置pom.xml路径:$(System.DefaultWorkingDirectory)/{zip file name}/pipelines-java-function-master/pom.xml

【讨论】:

    【解决方案2】:

    复制到暂存目录后尝试调用 Maven 构建命令。类似于下面的示例,因为 Maven 构建似乎正在查看暂存目录,并且在您的管道中,复制到暂存目录的步骤就在 Maven 构建步骤之后:

    # add these as the last steps
    # to deploy to your app service
    - task: CopyFiles@2
      displayName: Copy Files
      inputs:
        SourceFolder: $(system.defaultworkingdirectory)/target/azure-functions/
        Contents: '**'
        TargetFolder: $(build.artifactstagingdirectory)   
    
    - task: Maven@3
      inputs:
        mavenPomFile: 'pom.xml'
        mavenOptions: '-Xmx3072m'
        javaHomeOption: 'JDKVersion'
        jdkVersionOption: '1.8'
        jdkArchitectureOption: 'x64'
        publishJUnitResults: true
        testResultsFiles: '**/surefire-reports/TEST-*.xml'
        goals: 'package'
    

    【讨论】:

    • 谢谢。我在 CopyFiles 之后移动了 Maven 构建。现在出现错误:##[error] Unhandled: Not found SourceFolder: /home/vsts/work/1/s/target/azure-functions/
    • 好的,谢谢您的回答。另一个镜头:你说 pom 文件在一个 zip 文件中。您是否尝试解压缩所有内容并指出 Maven 构建中的 pom 文件,例如 /pipelines-java-function-master/pom.xml 而不是“pom.xml”?
    【解决方案3】:

    我有同样的问题。这是我解决问题的方法,因为从错误中可以看出进程无法找到 pom.xml。

    之前: -------- 脚步: - 任务:Maven@3 输入: mavenPomFile: 'pom.xml'

    之后: ------ 脚步: - 任务:Maven@3 输入: mavenPomFile: '/pom.xml'

    在我的例子中,项目名称是 azure-fun-demo,因此 mavenPomFile 的值将是 'azure-fun-demo/pom.xml'

    【讨论】:

      【解决方案4】:

      我通过转到“管道 > 更多选项 > 编辑”并从“浏览 POM maven 文件”中选择 pom.xml 解决了这个问题

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-07-04
        • 1970-01-01
        • 2020-05-19
        • 1970-01-01
        • 2021-11-23
        • 1970-01-01
        • 1970-01-01
        • 2020-08-27
        相关资源
        最近更新 更多