Azure JAVA Functions + DevOps pipeline for different environment

899 views Asked by At

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.

1

There are 1 answers

0
Kevin Lu-MSFT On BEST ANSWER

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.