Deployment of Azure Functions written in Java using the ftps task of Azure Pipelines

Maninderjit (Mani) Bindra
5 min readOct 15, 2018

--

This post is an extension of the Continuous Deployment of Azure Functions written in java using Azure Pipelines (Azure DevOps / VSTS). This post describes how the Azure DevOps FTP task can be used to push the Azure function to Azure.

It must be noted that the ideal way to deploy functions is using the App Service Deploy task which the main post describes. The ftp way of deployment is not recommended, however if this is the only option available to you due to some constraint, you may follow the rest of this post.

Visual Designer Based Pipeline

First we create a new Azure build pipeline, select the source as github, and point it to the git repository, and branch.

Next select the Maven template, and hit apply

The maven template adds 3 tasks, the maven task, the copy files task and the Publish artifact task. You can select the agent where this task is executed, in this sample the Hosted VS2017 agent has been selected. Next we configure the 3 tasks

Now we configure the maven task. Point it to the pom.xml

Now configure the copy files task. The configuration below results in all files and folders under the target/azure-functions directory being copied

The Publish Artifact task is configured to then publish all copied artifacts. The publish artifacts task is needed if you have a separate release pipeline.

Typically to push the artifacts to Azure we would create a new release linked to this build, but for the purpose of this post let us add a ftp upload task to the same build pipeline.

Now we configure the ftp upload task. First we need to get the values of the build variables ftps server url, ftps user name, and ftps password. The values of these variables can be retrieved following the steps mentioned in this post. Instead of hard coding these values into the pipeline, adding pipeline variables in the task makes pipeline more configurable.

Please note that due to the way this sample pipeline has been configured you do not need to have the site/wwwroot appended to the the end of the ftpserver url. The fourth variable we need to configure is the Maven target folder name (functionAppMvnTargetFolder), which we can get from the maven pom file as was discussed in main post. By default the overwrite files flag of the is set to true as shown in the screenshot below. We can also turn on the preserve file paths check box.

Now we configure the values of the 4 pipeline variables which will be used by the ftp upload task.

Thats it the visual designer pipeline is configured which is ready to continuously deploy code to the Azure function. Let us now look at a yaml file based depoyment pipeline which does the same tasks as the pipeline designed above.

Pipeline as code

The first step of creating the pipeline is the same as the earlier pipeline where we configure the git repository. In the next step we select the yaml based template.

Next we select the pipeline as code yaml file, which in the case of our example is the azure-pipelines.yaml.

Let us have a look at the pipeline yaml file:

resources:
- repo: self
queue:
name: Hosted VS2017
demands: maven
# Maven Package - create the function artifacts in
steps:
- task: Maven@2
displayName: 'Maven pom.xml'
inputs:
mavenPomFile: '$(mavenPOMFile)'
# Copy and Publish the azure-functions directory which
- task: CopyFiles@2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(system.defaultworkingdirectory)'
Contents: |
**/azure-functions/**

TargetFolder: '$(build.artifactstagingdirectory)'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
# Ftp artifacts to Azure functions
- task: FtpUpload@1
displayName: 'FTP Upload: To Function App ftp location'
inputs:
credentialsOption: inputs
serverUrl: '$(ftpsServerUrl)'
username: '$(ftpsUsername)'
password: '$(ftpsPassword)'
rootDirectory: '$(build.artifactstagingdirectory)/target/azure-functions/$(functionAppMvnTargetFolder)'
filePatterns: '**'
remotePath: '/site/wwwroot'
overwrite: true
preservePaths: true

These are the same tasks as the visual pipeline, and we need to set the same variable values. Just like the visual pipeline we can retrieve the ftp username, password and server url by following the steps detailed in this link. The only additional value we need to set is the mavenPOMFile variable. Let us look at the variable values:

The configuration of the yaml pipeline is complete as well. Now let us test the pipelines. Easiest way to test the continuous deployment is by changing the function app Java file and merging the changes into the repository.

--

--

Maninderjit (Mani) Bindra

Gopher, Cloud, Containers, K8s, DevOps | LFCS | CKA | CKS | Principal Software Engineer @ Microsoft