0

I have Azure Function project in JAVA. Unfortunately, java is not supported very well )-: So, everything is a "little" bit different. So, could you point me to reference example or documentation how to deploy a function project written in java to azure? Since all what I want shows just part of the problem - and the parts does not fit together )-:

  • java uses azure-function-maven-plugin (which is wrapper to func core tools)
  • this plugin prepares stagging folder which is compressed to ZIP and deployed as "package"
  • unfortunately, this stagging folder is named based of function name. So, ZIP package IS DEPENDENT on target azure RESOURCE name.

It is impossible to build independent package (ZIP) and deploy it to several different environment (stages/dev/test/prod). Or is it?

It is especially wierd when you use CI/CD pipeline. It is not possible to have one BUILD pipeline and than several DEPLOY pipeline. Because the build HAVE TO be named (internal directories) based on target deployment name - so not independent. Which goes against the basic principle to have one build and several configuration for each environment.

Any idea how to solve it without building several builds? Thank you.

EDIT: maven "mvn package (+azure-function:package)" prepare build with directories

${projectRoot}/target/azure-functions/${functionResourceName}/...

where

/... 

is compressed to final azure package named: ${functionResourceName}.zip

So, the "functionResourceName" is just in the name of ZIP file (+ containing jar with the same name). But ...

... if you try deploy this ZIP to azure function resource with another name - it fails.

6
  • Have you considered using Quarkus for this? There’s a guide which should help you through all steps involved: quarkus.io/guides/azure-functions-http Commented Oct 9, 2020 at 13:34
  • Wow, thanks. I was convinced that MS function did not support quarkus runtime. I will check it. Commented Oct 10, 2020 at 14:10
  • Do you mean that the folder name couldn't meet your requirements? When I run azure java funtion, it will generate azure function folder. I follow the steps in this blog.Can you share some screenshots about the package structure? You can also share the ideal state. Commented Oct 12, 2020 at 7:32
  • Based on my test, I try to use the same mvn command, and the zip file could be deployed to the azure function. I use the Auzre App Service Deploy task, although the functionappname is different, it is successfully deployed. Could you please share your deployment method. Commented Oct 14, 2020 at 9:12
  • I tried with mvn azure-functions:deploy. So, you prepared your package (ZIP) MANUALLY (as mentioned in linked blog) - NOT by maven goal. ... I checked it now and the ZIP package is NOT created by azure-functions:package goal as I thought. Which seems to me as a bug. This zip is created by deploy goal. Which confused me. I guess it will work - post it as SO answer and I will accept it. Thank you. Commented Oct 15, 2020 at 10:21

1 Answer 1

2

Yes. I indeed manually prepare the package(using Publish Build Artifacts Task.)

I would like to share my steps to deploy the Java Function Package to Azure Function.

Here are my steps:

In Build Pipeline:

steps:
- task: Maven@3
  displayName: 'Maven pom.xml'
  inputs:
    mavenPomFile: '$(Parameters.mavenPOMFile)'
    options: 'azure-functions:package'

- task: CopyFiles@2
  displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
  inputs:
    SourceFolder: '$(system.defaultworkingdirectory)'
    Contents: '**/azure-functions/**'
    TargetFolder: '$(build.artifactstagingdirectory)'
  condition: succeededOrFailed()

- task: ArchiveFiles@2
  displayName: 'Archive $(Build.ArtifactStagingDirectory)/target/azure-functions/kishazureappfunction'
  inputs:
    rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/target/azure-functions/kishazureappfunction'
    includeRootFolder: false

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

In Release Pipeline:

I use the Azure App Service Deploy Task. (For clear, I converted it to yaml format)

- task: AzureRmWebAppDeployment@4
  displayName: 'Azure App Service Deploy: kevin1014'
  inputs:
    azureSubscription: kevintest
    appType: functionApp
    WebAppName: kevin1014
    packageForLinux: '$(System.DefaultWorkingDirectory)/_123-Maven-CI/drop/1.zip'
    enableCustomDeployment: true
    DeploymentType: runFromZip

Result:

enter image description here

The azure function name and the package name is different. But it could be deployed to Azure Function successfully.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.