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://learn.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://learn.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://learn.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'
Advertisement
Answer
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