简体   繁体   中英

Unhandled: Not found mavenPOMFile - Azure DevOps pipeline for Java Function App

I would like to create pipeline which deploy Java Azure Function, but failing. Please advice me. I'm following tutorial as base, but I'm using Git Repo of Azure DevOps instead of GitHub. https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/java-function?view=azure-devops

POM File is located inside zip file of /pipelines-java-function-master/pom.xml

My Error is:

 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

My YAML is:

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'

Try to call Maven build command after copying to the staging directory. Something like in the example below, as it seems like the Maven build is looking at the staging directory, and in your pipeline the copy step to the staging directory is right after the Maven Build step:

# 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'

POM File is located inside zip file of /pipelines-java-function-master/pom.xml

This is the cause for why you encountered the error message Not found mavenPOMFile .

For most of tasks, there has built-in script will be called to extract the archived file once our system detect out there has one archived file exists in source.

BUT, for Maven task, we haven't provided such built-in scripts in it. At this time, the task will follow the normal work logic to try to find pom.xml through $(System.DefaultWokingDirectory) .

As you said, the pom.xml is located in a zip file. Since the zip hasn't been extracted, the zip will be treat as a file instead of a folder . In another word, the pom.xml seems never been exists for Maven task. Then task tell you, sorry, we can not find out pom.xml now.


Based on your scenario, you should run Extract file task to make the zip file extracted before Maven task ran.

Below the sample YAML script you can have a refer:

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'

Just pay attention to the value of mavenPomFile . Since the Extract file task will create a folder with the same name with zip file under working directory, please configure the pom.xml path with hard code: $(System.DefaultWorkingDirectory)/{zip file name}/pipelines-java-function-master/pom.xml

I had same issue. Here is how I resolved the issue as from the error its evident that the process is not able to find the pom.xml.

Before: ------- steps: - task: Maven@3 inputs: mavenPomFile: 'pom.xml'

After: ------ steps: - task: Maven@3 inputs: mavenPomFile: '/pom.xml'

In my case the project name was azure-fun-demo so mavenPomFile will have value as 'azure-fun-demo/pom.xml' .

I solved this issue by going to "Pipelines > More options > Edit" and pick pom.xml from "Browse POM maven file"在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM